开发者

mysql query not working no error ot anything

      $result53开发者_开发百科543534 = mysql_query("UPDATE users SET credit=credit+1 WHERE email= '{$battle_get['username']}'")
or die(mysql_error());

But does not update. checked $battle_get['username'] and the username is in there. i am not getting any errors or anything just not adding...

Any help would be very nice thanks in advance


See what the result from mysql_affected_rows() is:

if ( ! $result53543534 = mysql_query( "UPDATE users SET credit=credit+1 WHERE email= '{$battle_get['username']}'") ) {
    die( mysql_error() );
} else {
    echo "Number of rows affected: " . mysql_affected_rows() . "<br>";
}

I may not have the syntax completely right but I hope you get the idea. If the result is 0, you're not specifying the WHERE syntax so that it actually refers to any row(s).

If the result is greater than 0, then you're mistaken if you think it's not affecting any rows. It may not be affecting the rows you think it should, but that's another issue.

Also, echo your sql statement so you can actually see exactly what it's doing.


Try testing

$email = $battle_get['username'];
UPDATE users SET credit=credit+1 WHERE email= '$email'


you forgot about committing the query to database, try transaction

mysql_query("START TRANSACTION");
mysql_query("UPDATE users SET credit=credit+1 WHERE email= '{$battle_get['username']}'");
mysql_query("COMMIT");


I would suggest changing the code to as follows, it will allow you to examine the sql query. Try testing the sql query to see if it runs at all. You may also want to run DESCRIBE users on your mysql console to see what sort of information you get.

$sql = "UPDATE users SET credit=credit+1 WHERE email= '{$battle_get['username']}'"
echo $sql;
if ( ! $result53543534 = mysql_query($sql) ) {
    die( mysql_error() );
} else {
    echo "Number of rows affected: " . mysql_affected_rows() . "<br>";
}


Grant UPDATE permission to the user in the connection you're using for this. Just because the user is able to SELECT and INSERT, does not mean they can automatically UPDATE as well, you need to explicitly grant them the permission to UPDATE. And also mysql_error() will not show any error because your SQL statement is correct, hence no error shown.


Happen to me the same thing, what I did first was to reproduce it on MySQL Workbench then use the SQL sentences from there, I found out (not sure why) it works adding parenthesis after the WHERE clause:

UPDATE users SET credit = credit + 1 WHERE (`email`= '{$battle_get['username']}')


Please check you mention name=email And name=password attributes in all input field and also mention in name=submit in submit if it's input.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜