A PHP Error was encountered

Hi I have limited knowledge of PHP but can usually successfully find a part of code to recreate items in my website.
In this instance I am uploading a pdf to my db in my dahsboard and then calling it up in my website.

I already have one pdf on the page doing exactly this, so I have taken the code snippet in my admin views/controller/model and have recreated with new name and all works at dashboard end, it uploads the file into the correct place in my database, but the frontend is showing this message

View Drawing
2D Drawings
A PHP Error was encountered

Severity: Notice

Message: Undefined index: acccesories_fitting_pdf_file

Filename: views/index.php

Line Number: 104
" target="_blank">View Fitting Instructions

I have copied the previous pdf file which is the (view drawings) snippet which was acccesories_pdf_file exactly in every instance over all the relevant php files and changed it to acccesories_fitting_pdf_file where the original file name was but I cannot find anywhere in the controller to define it

I would appreciate any help

Without code it’s difficult to tell you specifically, but somewhere you are either doing this,

$_GET['acccesories_fitting_pdf_file'] 

or this

$_POST['acccesories_fitting_pdf_file']

And that key doesn’t exist.

Hi, I can post the code for the view and controller if that helps.

Controller PHP

<?php
 if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start(); //we need to call PHP's session object to access it through CI
class Accessories extends CI_Controller {
	function _remap($method_name = 'index')
	{
		if(!method_exists($this, $method_name)){
			$this->index();
		}
		else{
			$this->{$method_name}();
		}
	}
	function __construct()
	{
		parent::__construct();
		$this->load->model('accessories_model','',TRUE);
	}
 
 function index()
 {
	 //echo "index";
	//exit;
	$link = $this->uri->segment(2);
	//echo "<br/>";
	//echo $link;
	//exit;
	
	/*$accessories = $this->accessories_model->getdata('tbl_accessories_master');
	if(!empty($accessories) && count($accessories) > 0)
	{
		//echo "<pre>";
		//print_r($accessories);
		foreach($accessories as $key => $val)
		{
			$updateData = array();
			$updateData["link"] = (str_replace(' ', '-', strtolower($val['accessories_name'])));;
			
			$this->db->where("accessories_id",$val['accessories_id']);
			$this->db->update("tbl_accessories_master",$updateData);
			
		}
	} */
	
	 if(!empty($link))
	 {
		//echo "done";
		//exit;
		$data['accessories'] = $this->accessories_model->getdata('tbl_accessories_master','link',$link);
		
		 if(is_array($data['accessories']))
		 {
			$data['accessory_images'] = $this->accessories_model->getdata('tbl_accessories_images','accessories_id',$data['accessories'][0]['accessories_id']);
			//echo "<pre>";
			//print_r($data);
			//exit;
			$this->load->view('template/header.php');
			$this->load->view('accessories/index',$data);
			$this->load->view('template/footer.php');
		 }
		 else
		 {
			$this->load->view('template/header.php');
			$this->load->view('template/no-result.php');
			$this->load->view('template/footer.php');
		 }
	 }
	 else
	 {
		$this->load->view('template/header.php');
		$this->load->view('template/no-result.php');
		$this->load->view('template/footer.php');
	 }
	 
 }

}

?>

Index.php from views

<div class="container-fluid">

<?php
if(!empty($accessories) && !empty($accessories[0]['accessories_banner_image']))
{
?>
	<div class="row">
		<div class="col-sm-12 pl0 pr0">
		  <div class="product-banner-bg">
			  <img src="<?php echo base_url(); ?>images/accessories_images/<?php echo $accessories[0]['accessories_banner_image']; ?>" alt="" title="" class="img-responsive"/> 
			</div>        
		</div>
	</div>
<?php
}
?>

<div class="clearfix"></div>

<div class="container">
	<div class="row">
    	<div class="col-sm-12">
        	<div class="product-hd">Accessories</div>
            <div class="medium-hd"><?php echo $accessories[0]['accessories_name']; ?></div>
        </div>
    </div>
    <div class="row">
    	<div class="col-sm-12">
        	<div class="content">
            	<?php echo html_entity_decode($accessories[0]['accessories_description']); 

				/*<!--<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac libero vitae ligula fringilla sollicitudin non in lacus. 
                Aliquam non nulla at nisi maximus pharetra id at sapien. Pellentesque ullamcorper imperdiet ex. Praesent eu finibus nisl, id viverra
                 mauris. Sed iaculis erat a dolor mattis eleifend. Integer dolor augue, fermentum sed mauris a, pretium ornare ligula. Fusce ut 
                 orci sem. Curabitur sit amet neque sit amet erat scelerisque iaculis. </p>-->*/ ?>
            </div>
        </div>
    </div>
    
    <?php
	if(!empty($accessory_images) && count($accessory_images) > 0)
	{
	?>
    <div class="row">
    	<div class="col-sm-12">
			<div class="medium-hd"></div>
        	<div class="content">
            	<div id="links-install" class="links">
					<?php
					$accessory_img_cnt = 0;
					
					foreach($accessory_images as $acc_img)
					{
						$accessory_img_cnt = $accessory_img_cnt + 1;
					?>
						<div class="col-sm-3 mt15 mb15 product-border">
							 <a href="<?php echo base_url(); ?>images/accessories_images/<?php echo $acc_img['accessories_image']; ?>" title="Accessory image <?php echo $accessory_img_cnt; ?>">
							<img src="<?php echo base_url(); ?>images/accessories_images/<?php echo $acc_img['accessories_image']; ?>" alt="Accessory image <?php echo $accessory_img_cnt; ?>" class="img-responsive">
							</a>
						</div>
					<?php
					}
					?>
				</div>
            </div>
        </div>
    </div>
    <?php
	}
	?>
	
	<?php
	if(!empty($accessories[0]['accessories_pdf_file']))
	{
	?>
	
    <div class="row">
    	<div class="col-sm-12">
			<div class="medium-hd"></div>
        	<div class="content">
				<?php
				if(!empty($accessories[0]['accessories_pdf_file']))
				{
				?>
					<div class="bullet-box-content">
						<a href="<?php echo base_url(); ?>images/accessories_images/pdf/<?php echo $accessories[0]['accessories_pdf_file']; ?>" target="_blank">View Drawing</a>
					</div>
				<?php
				}
				
				if(!empty($accessories[0]['accessories_zip_file']))
				{
					?>
					<div class="bullet-box-content">
						<a href="<?php echo base_url(); ?>images/accessories_images/zip/<?php echo $accessories[0]['accessories_zip_file']; ?>" target="_blank">2D Drawings</a>
					</div>
				<?php
				}
				
				if(!empty($accessories[0]['accessories_fitting_pdf_file']))
				{
					?>
					<div class="bullet-box-content">
						<a href="<?php echo base_url(); ?>images/accessories_images/pdf/<?php echo $accessories[0]['acccesories_fitting_pdf_file']; ?>" target="_blank">View Fitting Instructions</a>
					</div>	
					<?php
				}
				?>
				
            </div>
        </div>
    </div>
    
    <?php
	}
	?>

</div>
<script>
	document.getElementById('links-install').onclick = function (event) 
	{
		event = event || window.event;
		var target = event.target || event.srcElement,
			link = target.src ? target.parentNode : target,
			options = {index: link, event: event},
			links = this.getElementsByTagName('a');
			blueimp.Gallery(links, options);
	};
</script>

I also have files in my dashboard but they seem to be working

In the view you have this,

And it gets its data from here:

So I would say it isn’t coming back. You can test what it does return by doing this,

if(is_array($data['accessories']))
{
    print_r($data['accessories'][0]);

Ok thanks I will test this when I return home and let you know :slight_smile:

I tried this and this is what I get back,

Array (
[accessories_id] => 58
[accessories_name] => PTS
[link] => pts
[accessories_banner_image] => ohm-pts-hardware.png
[accessories_description] => Small pan and tilt wall bracket

Size (h x w x d) (mm):

139.6 x 60 x 120.75
[accessories_pdf_file] => ohm_pts_drawing.pdf
[accessories_zip_file] => ohm_pts_drawing.zip
[status] => Active
[created_on] => 2019-04-29 16:46:17
[created_by] => 89
[updated_on] => 2018-03-07 20:32:11
[updated_by] => 89
[accessories_fitting_pdf_file] => ohm_lwbpt_drawing1.pdf
)

looking at that it is finding the correct file ohm_lwbpt_drawing1.pdf so I am now more confused.

could it be having a problem because there is already a PDF being downloaded on this page

here is link to page so you can see what I’m actually trying to do.

and I don’t know if this is relevant but if I click on the link for the view fitting instructions it is trying to take you here
http://www.ohm.co.uk/images/accessories_images/pdf/<div%20style=

which obviously doesn’t exist
thank you so much for your input

It took a minute to figure out the issue, and the issue is, it isn’t there! There is a very minute difference. To see what I mean, do a search for, acccesories_fitting_pdf_file in the array.

Astonecipher -
Damn all this time it was a spelling error 3 ccc 1 s in stead of 2cc 2ss now I feel really dumb, I can’t thank you enough, I’ve been pulling my hair out…

I guess it is true when they say fresh eyes…

I appreciate all your help.

Trace

Sponsor our Newsletter | Privacy Policy | Terms of Service