update statement using php mysql not working -



update statement using php mysql not working -

i have table below values:

table ----------------------------------------------------------- column | type | default ----------------------------------------------------------- name varchar(100) none logincount int(11) 0 lastlogindate datetime 0000-00-00 00:00:00 -----------------------------------------------------------

now, want check if user logged in , if yes, update logincount , lastlogindate correspondingly.

the php script below:

<?php // verification query.. if($row = mysql_fetch_array($result, mysql_assoc)){ $sql = "update table set `logincount` = `logincount` + 1, `lastlogindate` = now() `name` = '".$username"'"; $result = mysql_query($sql); } ?>

the issue is, not working!

however, if utilize same logging mysql console directly, update happens!

could please tell me doing wrong here?

thank you!

you're missing . concatenation before closing quote

where `name` = '".$username"'"; //------------------------^^^

should be

where `name` = '".$username . "'"; //--------------------------^^^

or better, omit concatenation because enclosing in double quotes.

$sql = "update `table` set ..... `name` = '$username'";

this means don't have error_reporting enabled, or see syntax error.

something like:

parse error: syntax error, unexpected '"'"' (t_constant_encapsed_string)...

ini_set('display_errors', 1); error_reporting(e_all);

finally, should not cause problems, wouldn't expect based on posted code, unwise reuse $result, result resource variable first (unseen here) query. not able fetch 1 time again later if needed, 1 time has been overwritten true/false update statement. utilize different variable update success/failure.

$other_var_not_result_for_clarity = mysql_query($sql);

php mysql sql-update

Comments

Popular posts from this blog

javascript - mongodb won't find my schema method in nested container -

Hibernate criteria by a list of natural ids -

ios - Lagging ScrollView with UIWebview inside -