I am trying to pass 2 variables to a form page.
one is a query for the form fields and the 2nd is a error variable.
when load the page, i get the following error:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: error
Filename: views/upload_form.php
Line Number: 7
Here is my controller:
<?php
class Upload extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->database();
}
function index()
{
$this->load->helper('url');
$this->load->model('Image_model');
$data['query'] = $this->Image_model->image_biz();
$this->load->view('upload_form', $data, array('error' => ' ' ));
}
function do_upload()
{
$config['upload_path'] = dirname($_SERVER["SCRIPT_FILENAME"]).'/uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '200';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
} else {
$image_data = array('upload_data' => $this->upload->data());
// can be add extra feature here.
$insert_data = array(
'image_file' => $image_data['upload_data']['file_name'],
'image_path' => $image_data['upload_data']['full_path'],
'image_ext' => $image_data['upload_data']['file_ext'],
'image_width'=> $image_data['upload_data']['image_width'],
'image_height' => $image_data['upload_data']['image_height'],
);
$this->db->insert('image', $insert_data);//load array to database
$this->load->view('upload_success', $image_data);
}
}
}
?>
Here is my view page "upload.php":
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<?php echo $error;?>
<?php echo form_open_multipart('upload/do_upload');?>
Image: <input type="file" name="userfile" size="20" /><br>
<label for="select">Business ID:</label>
<select name="image_bizID">
<?php foreach ($query->result() as $row) { ?>
<option value=""><?=$row->biz_id;?></option>
<?php } ?>
</select>
<br /><br />
<input type="submit" value="upload" />
</form>
</body>
</html>
Any help to solving this error would be greatly appreciated.
Thank you.