Jump to content

getting last auto incremented id and setting it as a variable ???


andrew_biggart

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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