Re: update

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux