Reputation: 27
UPDATE: The suggestion of the '' worked around $username. Thanks! But now, the table isn't actually getting updated from the $lastLoginTime.
I have some problem with my query that I can't seem to figure out for the life of me and I am at a halt.
Let's take a look at the code.
function checkTOS($preusergrab){
include("includes/opendb.php");
$query = "SELECT * FROM users WHERE username='".$preusergrab."'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_assoc($result)){
$resultset[] = $row;
$TOS = $row['acceptTOS'];
}
mysql_free_result($result);
if($TOS == 1){
// return to processor
$lastLoginTime = time();
$query = mysql_query("UPDATE users
SET lastLoginTime = '$lastLoginTime'
WHERE username = $username");
if (!$query) {
die('<br>Invalid query: ' . mysql_error());
}
}elseif($TOS == 0 || $TOS = ''){
header("Location: http://partner.domain.com/terms.php?action=show");
die();
}else{
echo 'Internal Application Error:';
echo 'Value unrecognizable.';
echo '<br>Please alert someone at [email protected]';
die();
}
}
Now, where the problem comes in is at this section:
$lastLoginTime = time();
$query = mysql_query("UPDATE users
SET lastLoginTime = '$lastLoginTime'
WHERE username = $username");
if (!$query) {
die('<br>Invalid query: ' . mysql_error());
}
It says the following:
Invalid query: Unknown column 'theuser' in 'where clause'
In this case, 'theuser' is the user that $preusergrab is representing.
In my table, the username is the primary key, row 0.
What could possibly be invalid if I know the row is there and everything else works?
Upvotes: 1
Views: 1225
Reputation: 1283
I believe you forgot to quote the $username, quote like so '$username'
$query = mysql_query("UPDATE users
SET lastLoginTime = '$lastLoginTime'
WHERE username = '$username'");
if (!$query) {
die('<br>Invalid query: ' . mysql_error());
}
Upvotes: 0
Reputation: 171381
It should be:
WHERE username = '$username'");
Note the apostrophes I added around your $username' variable.
Upvotes: 1
Reputation: 5714
try to
$query = mysql_query("UPDATE users
SET lastLoginTime = '$lastLoginTime'
WHERE username = '$username'");
Upvotes: 2