0

how can i name a file uploaded with the new id record just created in php and mysql, i am trying to identify files uploaded with their own id record generated by and auto-increment id field even if id are not in secuence. i have tried this :

$rs = mysql_query("SELECT MAX(id) AS id FROM $tb_1");
if ($row = mysql_fetch_row($rs)) {
    $id = trim($row[0]);

    }
    $id = $id+1;

but the problem is the last auto-incremente new id is differente in a secuence because i have delete last record and that change my view...

Andjeo
  • 1
  • 1
  • 1
    First save the data to the database and afterwards get lastinsertid and use it for your file renaming?! – Tobias Golbs Mar 05 '14 at 15:50
  • possible duplicate of [Get current AUTO\_INCREMENT value for any table](http://stackoverflow.com/questions/15821532/get-current-auto-increment-value-for-any-table) – Jasper Mar 05 '14 at 15:52
  • First check http://php.net/mysql_insert_id where you will find a better way to get the insert ID and also a notice about the mysql extension. And after that you can use that id to name your file – mishu Mar 05 '14 at 15:54
  • **+Tobias kun:** You mean, i have to insert the data and then recall the recorda and then update the fields? – Andjeo Mar 05 '14 at 22:51

1 Answers1

0

After your insert query, can you not do:

$id = mysql_insert_id();

That will store the ID in a variable for later.

BT643
  • 3,495
  • 5
  • 34
  • 55