Re: update

From: Date: Tue, 04 Feb 2003 13:17:42 +0000
Subject: Re: update
Groups: php.db 
Request: Send a blank email to php-db+get-25410@lists.php.net to get a copy of this message
UPDATE is for changing values in existing rows. It appears you want to add new information. Use INSERT. $query= "INSERT tablename SET (username, email, location) VALUES( $username, $email, $location)"; Note that a WHERE condition is incorrect for INSERT. Your UPDATE syntax is not correct either. Note that you need only one query to update any or all of the columns in a row. Using your example: $query="UPDATE tablename SET username=$username, email=$email, location=$location WHERE userID=$id"; Finally, your "Flash of Success" is not useful because it will print even when the query fails. Doug On Thu, 30 Jan 2003 13:34:41 -0500, Ike Austin wrote: >Hello, Newbie question. > >And can the same SQL portion of the code be written something like... >query= "UPDATE taablename SET (username, email, location) >VALUEs( $username, $email, $location)"; > >Any reason why this Update command would not execute? > >// BUILD AND EXECUTE QUERY TO SAVE USER INFO INTO DATABASE TABLE >query = "UPDATE forumUsers SET username = '$name' WHERE userID = >'$id'"; >result = @mysql_query($query); >query2 = "UPDATE forumUsers SET email = '$emai' WHERE userID = >'$id'"; >result2 = @mysql_query($query2); >query3 = "UPDATE forumUsers SET Location = '$loc' WHERE userID = >'$id'"; >result3 = @mysql_query($query3); > >/ INFORM FLASH OF SUCCESS >print "&/:result=Updated Thanks"; >// CLOSE LINK TO DATABASE SERVER >ysql_close($link); >?> > > >Ike

« previous php.db (#25410) next »