
May 15th, 2008, 09:28 PM
|
|
Contributing User
|
|
Join Date: Apr 2007
Location: Brisbane
Posts: 129
Time spent in forums: 7 h 30 m 4 sec
Reputation Power: 2
|
|
|
logic - Item ID numbers
Hey guys...
I insert a product into the database... now I want to get the ID of that product just inserted.
The way I am doing it now works fine, but I feel its a bit dodge... It just might have a glitch if there are heaps of people adding a product at once...
Code:
// insert the item into the database //
$gitem_insert = gitem_insert($cat, $subcat, $title, $price, $description, $state, $suburb, $phone, $email, $cnote);
$query = mysql_query($gitem_insert);
// crunch time //
if($query){
// gather the ID of the new added element //
$last_gitem = last_gitem();
$queryn = mysql_query($last_gitem);
while($row = mysql_fetch_assoc($queryn)){
$id = $row['product_id'];
}
// FORM: image //
if(($_FILES['image']['type'] == "image/pjpeg") || ($_FILES['image']['type'] == "image/jpeg") || ($_FILES['image']['type'] == "image/gif")){
// Gather details INCASE we need to resize //
$filelol = $_FILES['image']['tmp_name'];
$source = imagecreatefromjpeg($filelol);
$destination = "images/gitems/$id-m-gitem.jpg";
$quality = 70; // image quality //
$limits = 300; // max width //
// call the function to resize the image //
image_resize($filelol, $source, $destination, $limits, $quality);
}
}
As you can see, I use the product ID in the image name... But... It's done dodge... what if 2 people add products at the exact same time...
Any tips, suggestions or someone possible tell me the CORRECT way to do this.. haha...
Thanks in advance guys!
Richie
__________________
- Richie
|