Board index   FAQ   Search  
Register  Login
Board index php forum :: Database phpMyAdmin

problem with query plz help

How to use phpmyadmin.... phpmyadmin related arguments. Even phpMyAdmin issues

Moderators: macek, egami, gesf

problem with query plz help

Postby atroz » Fri Oct 24, 2003 12:25 pm

hi all
anyone know how can i update the last row in the table i try with LAST_INSERT_ID but dont work to me.
i try something like this

UPDATE table1 set item1='bar' WHERE id = LAST_INSERT_ID()

THX a lot
atroz
New php-forum User
New php-forum User
 
Posts: 3
Joined: Fri Oct 24, 2003 12:12 pm

Postby toweter » Fri Oct 24, 2003 1:24 pm

try it like that:
mysql_query("UPDATE table1 set item1='bar' WHERE id = ".LAST_INSERT_ID());
toweter
New php-forum User
New php-forum User
 
Posts: 26
Joined: Sat Aug 30, 2003 9:04 am

Postby swirlee » Fri Oct 24, 2003 1:42 pm

toweter wrote:try it like that:
mysql_query("UPDATE table1 set item1='bar' WHERE id = ".LAST_INSERT_ID());


Um, toweter.. LAST_INSERT_ID() is a MySQL function, not a PHP function, so it has to be part of the query. PHP will just throw a "undefined function" error.

Anyway, atroz, I'm guessing that the problem here is that, to quote the docs, "The last ID that was generated is maintained in the server on a per-connection basis." I'm guessing that between the time you create the record and when you try to UPDATE it, you've since created a new connection (e.g. you're running a different script or a different instance of the script).

You could just use MAX(id) instead, I suppose.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back


Return to phpMyAdmin

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron