newbreed65 Posted April 6, 2009 Share Posted April 6, 2009 As you will see from the code below i have a MYSQL Query which adds a person data to my database, but when it come to the next part were i upload the persons image (if they have added one) I want to use the value from the primary key (person_id) ) that is Auto incremented as the images name, is there away to just get the ID instead if running another query like you would if you were displaying the data on a page $sql = "INSERT INTO team (person_firstname, person_surname, person_role, person_info, person_image) VALUES ('" . mysql_real_escape_string($firstname) . "', '" . mysql_real_escape_string($surname) . "', '" . mysql_real_escape_string($role) . "', '" . mysql_real_escape_string($info) . "', '" . mysql_real_escape_string($image) . "')" ; mysql_query($sql, $conn) or die('Could not submit person; ' . mysql_error()); //if image true then upload image if ($image == true) { require_once '../../includes/image_upload.php'; } Link to comment https://forums.phpfreaks.com/topic/152835-solved-getting-the-primarys-auto-incremented-val-right-after-a-new-record-is-inserted/ Share on other sites More sharing options...
phil88 Posted April 6, 2009 Share Posted April 6, 2009 mysql_insert_id() will do it. Link to comment https://forums.phpfreaks.com/topic/152835-solved-getting-the-primarys-auto-incremented-val-right-after-a-new-record-is-inserted/#findComment-802592 Share on other sites More sharing options...
newbreed65 Posted April 6, 2009 Author Share Posted April 6, 2009 thank u :-D Link to comment https://forums.phpfreaks.com/topic/152835-solved-getting-the-primarys-auto-incremented-val-right-after-a-new-record-is-inserted/#findComment-802593 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.