I have to update my the filename field after I insert info into it for purpose of retireving the last insert id. I am using pdo as my db connection and everything else. The questionis that why will the code below not even execute. do i have to use bindParam or use exec or something along those lines
// Retrieve the ID from the last insert $new_id = $db->lastInsertId(); $filetype = $photos_uploaded['type'][$counter]; $extention = $known_photo_types[$filetype]; $filename = $new_id.".".$extention; //mysql_query( "UPDATE gallery_photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" ); $select = $db->prepare("UPDATE gallery_photos SET photo_filename='".$filename."' WHERE photo_id='".$new_id."'"); $select->execute();
And what does your mysql server say about your query?
mysql doesn't say anything about it it just gets skipped over I know this because I look at the database everytime i insert something into
If no error came up it means your UPDATE query is OK and this condition if not satisfied photo_id=$new_id...
it doesn't even the filename i have and insert before the code above that file insert the file name as 0 then it is suppose to update to the actually file name but it doesn't. Seems like php is just skipping right over the satement.
Did u echo this:
"UPDATE gallery_photos SET photo_filename='".$filename."' WHERE photo_id='".$new_id."'"
and put it in phpmyadmin to see if is working (if is updating)?
i have two different versions of this script the sql works but the problems how it is working with pdo. my other version of the script uses mysql statements and everything in it works fine.
I assume from the first time that $new_id is empty and thats why the update is not updating and the problem could have been here:
$new_id = $db->lastInsertId();
, if not, u should debug your pdo class to see where your script stops ...
the lastinsertid function works i think that it is how I am calling the sql it don't know if it should be like select = db->exec or select = db->prepare or select = db->query. I have search the web for advice but there is very little info on the web about pdo and php.net doesn't have much for what I am trying to do