Welcome Guest, Not a member yet? Register   Sign In
Php Syntax not working on this line
#1

So I'm new here i now that because of this basic problem, once hi everyone and thats my problem in php framework in codeigniter.
I'm using Netbeans ide and wamp server.

this is my controller codes I'm have a database like Id Picture Profile and more. so i put in data in database and i want to uptade my Picture coloumn like this.
PHP Code:
public function Picture_Upload($id){
 
       
             $data
["$id"]=$id;
 
            $this->load->view('admin\add_products_picture',$data);
    }
 
        public function Save_picture($id){
 
               $data["$id"]=$id;
 
                
                $config
['upload_path'         './upload/';
 
               $config['allowed_types'       'gif|jpg|png';
 
               $config['max_size'            100;
 
               $config['max_width'           1024;
 
               $config['max_height'          768;

 
               $this->load->library('upload'$config);

 
               if ( ! $this->upload->do_upload('Picture'))
 
               {
 
                       
                        $error 
$this->upload->display_errors();
 
                       $this->session->set_flashdata("msj","Someting goes wrong try again".$error);
 
                       $this->load->view('admin/add_product_picture',$data);
 
               }
 
               else
                
{
 
                       $upload_data $this->upload->data();
 
                       $data=array(
 
                         'Picture'=>$upload_data["file_name" 
                        
);
 
                       $this->load->model('Database_Model');
 
                       $this->Database_Model->update_data("Products",$data,$id);
 
                     
                        redirect
(base_url().'admin/Products');
 
               }
 
       
            
    
}
    


           

here is my Database_model

PHP Code:
  public function update_data($tablo,$data,$id){
 
               $this->db->where('id',$id);
 
               $this->db->update($tablo,$data);
 
               return true;
 
           


and this is the form of all of this.

PHP Code:
<?php
$this
->load->view('admin\_header');
 
   
?>

<div id="page-wrapper">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-4">
                       
                        <h1 class="page-header">Add</h1>
                        <?php if($this->session->flashdata("msj")) { ?>
                         <div class="alert alert-info">
                             <a href="#" class="alert-danger">Sometings Go Wrong</a>
                             <br>
                                <?=$this->session->flashdata("mesaj");?> 
                                
                            </div>
                        <?php ?>
                        <form  method="POST" enctype="multipart/form-data" action="<?=base_url()?>admin/product/Save_Picture/<?=$id?>" >
                            <div class="form-group">
                            <label for="exampleInputEmail1">Save Picture</label>
                            <input type="file" class="form-control" id="pic" required name="pic"  >
                          </div>
                          <button type="submit" class="btn btn-primary">Send</button>
                        </form>
                    <!-- /.col-lg-12 -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.container-fluid -->
        </div>
</div>
<?php
$this
->load->view('admin\_footer');
?>


this is all to my codes so now i cant get to id like this 
action="<?=base_url()?>admin/product/Save_Picture/<?=$id?>"
browser give me error like that : 
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: id

Filename: admin/add_product_picture.php

Line Number: 20

and i can not get it to image id so i cant uptade to data base but the picture comes from to uploads file so database not updating. there are still empty. when i was write to <?php $id ?> there is a no error around but so still i cant get to id and name of image in database.

if you know and tell me i will thanks a lot for this. thanks for helping or trying to this if you want i can share my code in github.

i'm student of computer engineering in Turkey, and sorry for my Bad English.
Reply
#2

(12-10-2017, 04:22 AM)Redwoodcutter Wrote:
PHP Code:
public function Picture_Upload($id){
 
       
             $data
["$id"]=$id;
 
            $this->load->view('admin\add_products_picture',$data);
    }
.............. 

          

Use
Code:
$data["id"]=$id;

instead of
Code:
$data["$id"]=$id;

And then the template will have your id variable.
Reply
#3

(12-10-2017, 04:22 AM)Redwoodcutter Wrote: So I'm new here i now that because of this basic problem, once hi everyone and thats my problem in php framework in codeigniter.
I'm using Netbeans ide and wamp server.

this is my controller codes I'm have a database like Id Picture Profile and more. so i put in data in database and i want to uptade my Picture coloumn like this.
PHP Code:
public function Picture_Upload($id){
 
       
             $data
["$id"]=$id;
 
            $this->load->view('admin\add_products_picture',$data);
 }
 
        public function Save_picture($id){
 
               $data["$id"]=$id;
 
                
                $config
['upload_path'         './upload/';
 
               $config['allowed_types'       'gif|jpg|png';
 
               $config['max_size'            100;
 
               $config['max_width'           1024;
 
               $config['max_height'          768;

 
               $this->load->library('upload'$config);

 
               if ( ! $this->upload->do_upload('Picture'))
 
               {
 
                       
                        $error 
$this->upload->display_errors();
 
                       $this->session->set_flashdata("msj","Someting goes wrong try again".$error);
 
                       $this->load->view('admin/add_product_picture',$data);
 
               }
 
               else
                
{
 
                       $upload_data $this->upload->data();
 
                       $data=array(
 
                         'Picture'=>$upload_data["file_name" 
                        
);
 
                       $this->load->model('Database_Model');
 
                       $this->Database_Model->update_data("Products",$data,$id);
 
                     
                        redirect
(base_url().'admin/Products');
 
               }
 
       
            
 
}
 


           

here is my Database_model

PHP Code:
  public function update_data($tablo,$data,$id){
 
               $this->db->where('id',$id);
 
               $this->db->update($tablo,$data);
 
               return true;
 
           


and this is the form of all of this.

PHP Code:
<?php
$this
->load->view('admin\_header');
 
   
?>

<div id="page-wrapper">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-4">
                       
                        <h1 class="page-header">Add</h1>
                        <?php if($this->session->flashdata("msj")) { ?>
                         <div class="alert alert-info">
                             <a href="#" class="alert-danger">Sometings Go Wrong</a>
                             <br>
                                <?=$this->session->flashdata("mesaj");?> 
                                
                            </div>
                        <?php ?>
                        <form  method="POST" enctype="multipart/form-data" action="<?=base_url()?>admin/product/Save_Picture/<?=$id?>" >
                            <div class="form-group">
                            <label for="exampleInputEmail1">Save Picture</label>
                            <input type="file" class="form-control" id="pic" required name="pic"  >
                          </div>
                          <button type="submit" class="btn btn-primary">Send</button>
                        </form>
                    <!-- /.col-lg-12 -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.container-fluid -->
        </div>
</div>
<?php
$this
->load->view('admin\_footer');
?>


this is all to my codes so now i cant get to id like this 
action="<?=base_url()?>admin/product/Save_Picture/<?=$id?>"
browser give me error like that : 
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: id

Filename: admin/add_product_picture.php

Line Number: 20

and i can not get it to image id so i cant uptade to data base but the picture comes from to uploads file so database not updating. there are still empty. when i was write to <?php $id ?> there is a no error around but so still i cant get to id and name of image in database.

if you know and tell me i will thanks a lot for this. thanks for helping or trying to this if you want i can share my code in github.

i'm student of computer engineering in Turkey, and sorry for my Bad English.

$data["$id"]=$id; to $data["id"]=$id;
Reply
#4

thanks a lot problem is solved i cant see that.

and guys dont write to kod while you are sleeping Smile
Reply




Theme © iAndrew 2016 - Forum software by © MyBB