genista Posted August 11, 2015 Share Posted August 11, 2015 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 Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted August 11, 2015 Share Posted August 11, 2015 this is the first prepared query in your code - $stmt = $DB_con->prepare(" ... "); this is the second one, where the error is at - $stmt->$DB_con->prepare($query); look at what is different in those, right after the $stmt variable. Quote Link to comment Share on other sites More sharing options...
genista Posted August 13, 2015 Author Share Posted August 13, 2015 Doh! Spot on, thanks for pointing that out Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.