problems adding data to field using WHERE

A

Anonymous

Guest
<?php
require("../auth_user.inc.php");
require("../conn.inc.php");

$ip4status = 'completed';
$username = $_SESSION['user_logged'];

$sqlstatement = "INSERT INTO user_info (ip4status) value ('$ip4status') WHERE username = $username";

$sql_result = mysql_query($sqlstatement) or die("Couldn't input into database, please contact your system administrator: $sqlstatement - " . mysql_error());

?>

All i want todo is is update a field in the record of the user thats logged in so the column ip4status reads complete

But i keep getting following and i cant work out why

Couldn't input into database, please contact your system administrator: INSERT INTO user_info (ip4status) value ('completed') WHERE username = chris - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE username = chris' at line 1

any ideas, cheers for any help
 
so this instead? (ive added a time thing too)


<?php
require("../auth_user.inc.php");
require("../conn.inc.php");

$ip4status = 'completed';
$username = $_SESSION['user_logged'];
$ip4time = date("d, n, Y – H:i:s");

$sqlstatement = "UPDATE user_info ('ip4status', 'ip4comptime') values ('$ip4status', '$ip4time') WHERE username = $username";

$sql_result = mysql_query($sqlstatement) or die("Couldn't input into database, please contact your system administrator: $sqlstatement - " . mysql_error());

?>

this returns pretty much the same error
 
i would use SET syntax with UPDATE..

UPDATE
user_info
SET
ip4status = '$ip4status',
ip4comptime = '$ip4time'
WHERE
username = $username"
LIMIT 1
 
Parse error: syntax error, unexpected T_STRING in C:\Program Files\Apache Group\Apache2\htdocs\levelone\ip4complete.php on line 10

line 10 = user_info

weird beacuse thats the correct name of my table
 
This error is not a MySql error but a PHP error. It doesn't recognize that user_info is still part of the string you're building...

Try this:

Code:
$query = <<<__SQL__
UPDATE 
user_info 
SET 
ip4status = '$ip4status', 
ip4comptime = '$ip4time' 
WHERE 
username = $username" 
LIMIT 1
__SQL__;

Coditor
 
I see i missed one thing in the query syntax and therefore there are some problems with parsing.
Coditor: your suggestion would also result in an error, however this time it will be query-parse error.

The query should be as follows:

Code:
UPDATE
 user_info
SET
 ip4status = '$ip4status',
 ip4comptime = '$ip4time'
WHERE
 username = $username
LIMIT 1

so the whole code would look like:

Code:
<?php
require("../auth_user.inc.php");
require("../conn.inc.php");

$ip4status = 'completed';
$username = $_SESSION['user_logged'];
$ip4time = date("d, n, Y – H:i:s");

$sqlstatement = "UPDATE
 user_info
SET
 ip4status = '".$ip4status."',
 ip4comptime = '".$ip4time."'
WHERE
 username = '".$username."'
LIMIT 1";

$sql_result = mysql_query($sqlstatement) or die("Couldn't input into database, please contact your system administrator: $sqlstatement - " . mysql_error());

?>
 
Back
Top