1

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?

1
  • 1
    i recommend putting your SQL query into a variable, echoing it, then copy and pasting it into PHPMyAdmin. This will tell you whether its your PHP or SQL that is at fault. Commented May 14, 2012 at 14:28

3 Answers 3

2

try to

$query = mysql_query("UPDATE users 
                SET lastLoginTime = '$lastLoginTime' 
                    WHERE username = '$username'");
Sign up to request clarification or add additional context in comments.

3 Comments

check that time() returns date in appropriate format understandably to mysql
Yes, standard unix timestamp, i use it everywhere else on the app. Just echoed the variable as well and it showed the timestamp.
print out "UPDATE users SET lastLoginTime = '$lastLoginTime' WHERE username = '$username'" for debugging (post it here please) and run this query by console mysql-client. let's see )
1

It should be:

WHERE username = '$username'"); 

Note the apostrophes I added around your $username' variable.

Comments

0

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());
}

1 Comment

Well that worked, but some reason it doesnt update the table.. I updated my question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.