Re: Not quite relevant question about coding and query

From: Date: Fri, 19 Jan 2001 07:33:00 +0000
Subject: Re: Not quite relevant question about coding and query
Groups: php.general 
Request: Send a blank email to php-general+get-35584@lists.php.net to get a copy of this message
Addressed to: "Jacky@lilst" <jacky@activelifestyle.com> php-general@lists.php.net ** Reply to note from "Jacky@lilst" <jacky@activelifestyle.com> Fri, 19 Jan 2001 14:00:02 -0600 > > Sorry, I think it should be like this: > > $queryInsert = "insert into user values > ('firstname','lastname','email')"; > $resultinsert = mysql_query($queryInsert); > > $UserIdLatest = mysql_insert_id(userId); > > > Is that correct? Yes, that is the 'proper' way to find out the value of a auto_incremant field. The SELECT MAX( userid ) method will work fine in testing, but then you get to pull your hair out when it starts to fail under heavy load. You might have a bit of a problem with the values() clause of the insert. That statement expects you to list all the entries in the table, in the order they appear, unless you specify a list right after the table name. I've given up on that syntax in favor of this one: $QueryInsert = "INSERT INTO user SET " . " firstname = '$FirstName', " . " lastname = '$LastName', " . " email = '$Email' ); It also works with update: $QueryUpdate = "UPDATE user SET " . " firstname = '$FirstName', " . " lastname = '$LastName', " . " email = '$Email' . "WHERE userId = 1234 " ); I like the fact that you can list any fields in any order while leaving out anything you want. Rick Widmer Internet Marketing Specialists http://www.developersdesk.com

« previous php.general (#35584) next »