Jump to content

Updating Database problem


genista

Recommended Posts

Hi,

 

I am working my way through an image upload process and writing the file name to the database, which is where I am getting stuck. I am getting the error: PHP Catchable fatal error: Object of class PDO could not be converted to string on this piece of code (taken from the larger piece below):

 

$stmt->$DB_con->prepare($query); 

 

Here is the full code from the script:

 

userid = $_SESSION['user_session']; 
$stmt = $DB_con->prepare("SELECT rideid, userid, make, model, image1 FROM ride1 WHERE userid= :userid"); 
$stmt->execute(array(":userid"=>$userid)); 
$userRow=$stmt->fetch(PDO::FETCH_ASSOC); 

$image1 = $userRow['image1']; 
$rideid = $userRow['rideid']; 


  
 if( ( $image1 == '' ) )    
      { 



$ds          = DIRECTORY_SEPARATOR;  //1 
  
$storeFolder = '../ride_images';   //2 
  
if (!empty($_FILES)) { 
      
    $tempFile = $_FILES['file']['tmp_name'];          //3              
       
    $targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;  //4 
      
    $image1 =  $targetPath.$userid.$rideid. $_FILES['file']['name'];  //5 
  

    move_uploaded_file($tempFile,$image1); //6 
   
    $query ="UPDATE ride1 SET image1= :image1 WHERE rideid= :rideid";  
$stmt->$DB_con->prepare($query);  
/* However, you pull your data in, I just used $image1 & $rideid for the example */  
$stmt->execute([ ':image1' => $image1, ':rideid' => $rideid ]);  

 

Any help you can give would be much appreciated.

 

Thanks,

 

G

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.