2

I'm trying to create a new row, in which the image name is the same as the recordID (plus '.png'). The recordID is an auto-incremented int.

This makes a new record:

mysql_query("INSERT INTO record (name,age) VALUES ('$name','$age'')");

..and this gets the recordID:

$newRecordID = mysql_insert_id();

but how do stick the recordID's value into a image_name column (plus '.png'), without having to search for it again?

cannyboy
  • 24,180
  • 40
  • 146
  • 252

3 Answers3

2

You don't need to stick '.png' to your image at all, your logic implies that each record contains info about image with extension png. Why would you even need another column then to store the image name?

The second part is that you are using a reserved word for your column name. Keyword NAME is reserved, you should always avoid it.

Michael J.V.
  • 5,499
  • 1
  • 20
  • 16
  • you're right. i should really just make it a boolean - 'hasImage'... btw, i was using $name as an example – cannyboy May 18 '11 at 13:17
0

Best I'm aware MySQL offers no sequence manipulation functions. So you can't.

The best you can do is to wrap this in a stored procedure to avoid a round trip to the server.

Denis de Bernardy
  • 75,850
  • 13
  • 131
  • 154
0

Maybe im missing somthing here but

mysql_query("INSERT INTO image (name,id) VALUES ("$newRecordID".'.png','$newRecordID')"); 
Rob
  • 1,235
  • 2
  • 19
  • 44
  • You're missing this: `$newRecordID` is generated during the insert. He'd like to access it while doing the insert, but cannot because MySQL offers no `currval()` function for sequences -- only auto_increment. – Denis de Bernardy May 16 '11 at 15:30