Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the ID of a mysql row before INSERT

I can get the ID just after INSERT by mysql_insert_id(); but I want to save an image in the form of ID-image_name.jpg and save it in a column named Image_Name. How can I save the image with forthcoming ID? Or it is better to save the image file after INSERT process?

like image 616
Googlebot Avatar asked Dec 22 '22 08:12

Googlebot


1 Answers

Saving it after the INSERT process is the most straightforward way.

mysql_query("INSERT INTO....."); // etc. etc.
$id = mysql_insert_id();
mysql_query("UPDATE table SET image = '$image_name' WHERE id = '$id'");
like image 195
Pekka Avatar answered Dec 24 '22 00:12

Pekka