I have a table with the below values:
Table
-----------------------------------------------------------
Column | Type | Default
-----------------------------------------------------------
name varchar(100) none
loginCount int(11) 0
lastLoginDate datetime 0000-00-00 00:00:00
-----------------------------------------------------------
Now, I want to check if the user is logged in properly and if yes, update loginCount and lastLoginDate correspondingly.
The php script is as below:
<?php
// Verification query..
if($row = mysql_fetch_array($result, MYSQL_ASSOC)){
$sql = "UPDATE table
SET `loginCount` = `loginCount` + 1,
`lastLoginDate` = now()
WHERE `name` = '".$username"'";
$result = mysql_query($sql);
}
?>
The issue is, this is NOT working!
However, if I use the same by logging into mysql console directly, the update happens!
Could you please tell me what am I doing wrong here?
Thank you!
if (!$result) echo mysql_error();echo $sqlto see the query that is going to be executed.mysqlextension for php, rather start usingmysqli, it is almost the same and you won't find it difficult to switch.mysqlis soon going to be deprecated and php will most probably not bundle it in the next release.$result === FALSE, then you must checkecho mysql_error();. Also, you have already used$resultas the resource for your first query. Even though you have done only one fetch call and it shouldn't collide, I recommend using a different variable for the secondmysql_query()call to cause less confusion.