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
https://forums.phpfreaks.com/topic/297721-updating-database-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.