Forums

PHP

This topic is locked

INSERT A BLANK ROW

Posted 27 Feb 2008 15:58:10
1
has voted
27 Feb 2008 15:58:10 Gerard Mariscalchi posted:
Hi there!

I wish to insert a blank row in a MySQL table and get as result the id of this row.
Purpose of this operation is to make later an update of this row with collected data.

How should I write the query?

Many thanks in advance for your help!

Best regards,

Gerry

Replies

Replied 28 Feb 2008 10:26:02
28 Feb 2008 10:26:02 Alan C replied:
Hi
it seems an odd thing to do because you could set the id (key) to auto-increment and then every time you insert into the table the record gets the next available id

later you can select the record using any of the fields with a query,

but if you really want to do it then you could write an update query where all the fields were null or dummy values like empty strings

Replied 28 Feb 2008 11:40:31
28 Feb 2008 11:40:31 Gerard Mariscalchi replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
it seems an odd thing to do because you could set the id (key) to auto-increment and then every time you insert into the table the record gets the next available id
later you can select the record using any of the fields with a query,
but if you really want to do it then you could write an update query where all the fields were null or dummy values like empty strings
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

Thanks for your reply!
Purpose of the operation is to reserve a row id to give the client order a number and after it has verified its order to fill the row with the entered data.
Getting the next auto_increment wasn't a good idea because of the possibility of simultaneous operations by two or more clients.
So, I changed my mind:
1 - I insert an empty row
2 - I update the row

I found the query for step 1:

<pre id=code><font face=courier size=2 id=code>mysql_query("INSERT INTO $table VALUES ()";
$inserted_id = mysql_insert_id();
print "&ordernumber=".$inserted_id;</font id=code></pre id=code>

Step 2 is easy...

Best regards,
Gerry
Replied 28 Feb 2008 21:06:26
28 Feb 2008 21:06:26 Alan C replied:
HI again,

sensible when you know the reason <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

good luck with the project

Reply to this topic