2

I am trying to update 2 or more rows on my MySQL with one code, this what I got now.

mysql_query("UPDATE users SET auth='yes' AND authtime='$time' WHERE username='$_GET[username]'"); 

the auth='yes' is 0 for some reason and authtime'$time' hasn't change from no to 1368135045

Can anyone help?

hanleyhansen
  • 6,304
  • 8
  • 37
  • 73
MBell86
  • 79
  • 1
  • 9

3 Answers3

1

To change the value of more than one column, use a comma delimiter between the column assignments, like this:

UPDATE mytab SET col1 = val , col2 = val WHERE ...
                            ^
                            +----- comma here

Your query is valid syntax, and it's executing successfully. But your query is of the form:

UPDATE users SET auth = (expression) WHERE username='$_GET[username]'

The problem is that query has an AND keyword where you want a comma delimiter.

What's happening is MySQL is reading that AND as part of the expression being assigned to the column auth. MySQL is evaluating this expression:

'yes' AND authtime='$time'

MySQL is evaluating that as a boolean expression, and taking the result of the boolean expression (which is FALSE), and assigning that result to column auth. (And that's the only column your statement is assigning a value to.)

spencer7593
  • 106,611
  • 15
  • 112
  • 140
1

try this ,will work surely

UPDATE users SET auth='yes' ,  authtime='$time' WHERE username='$_GET[username]'
vignesh pbs
  • 418
  • 2
  • 5
  • 16
0

You have syntax error in UPDATE.

Change:

UPDATE users SET auth='yes' AND authtime='$time' WHERE username='$_GET[username]'  

To:

UPDATE users SET auth='yes', authtime='$time' WHERE username='$_GET[username]'
Ravinder Reddy
  • 23,692
  • 6
  • 52
  • 82