andrew_biggart Posted May 29, 2008 Share Posted May 29, 2008 after adding a product i would like to get the last added item id and then set it as a variable! im usuing the following code if anyone can help! Thanks <? include("config.php"); if ($_POST['submit2']) { $prousid = ($_POST['prousid']); $protit=($_POST['protit']); $prouspri=($_POST['propri']); $proudes=($_POST['prodes']); $day=($_POST['day']); $month=($_POST['month']); $year=($_POST['year']); $hour=($_POST['hour']); $min=($_POST['min']); $catid=($_POST['catid']); // Where you want the files to upload to $uploaddir = "images"; // Where you want the files to upload to // Upload Part if(is_uploaded_file($_FILES['file']['tmp_name'])) { move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']); //insert item and image into the database $inssql = "INSERT INTO $tbl_name (user_id, category_id, item_image, item_name, item_starting_price, item_description, end_year, end_month, end_day, end_hour, end_min ) VALUES( '$prousid', '$catid','" . $_FILES['file']['name']. "', '$protit', '$prouspri', '$proudes', '$year', '$month', '$day', '$hour', '$minute')"; mysql_query($inssql); $item_id=mysql_insert_id() ; echo "<br/>"; echo "<br/>"; echo "Success, Your product has now been added to urbanwear's databases and is now able to be bidded on."; echo "<br/>"; echo "<a href='item_details.php?id="$item_id"'>" Click hear to view your item "</a>"; echo "<br/>"; echo "Thankyou for using www.urbanwear.co.uk number 1 for buying and selling urban clothing... "; echo "<br/>"; } else { echo "OPSY !! .. There was a problem with something, please go back and make sure everything has been entered correctly"; } } mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/107732-getting-last-auto-incremented-id-and-setting-it-as-a-variable/ Share on other sites More sharing options...
trq Posted May 29, 2008 Share Posted May 29, 2008 You really ought make yourself familiar with the manual. mysql_insert_id(). Link to comment https://forums.phpfreaks.com/topic/107732-getting-last-auto-incremented-id-and-setting-it-as-a-variable/#findComment-552283 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.