drn61317 2011-05-28 09:03
浏览 55

PHP MySql查询在更新后显示旧值

I am updating a value in a sql table and then printing the value, it is still showing old value.

<?
print_r(mysql_fetch_array(mysql_query("select visits from Orders")));
mysql_query("update Orders set visits=visits+1");
print_r(mysql_fetch_array(mysql_query("select visits from Orders")));
?>

It outputs 1 and then again 1. The second value should be 2. When I check in PhpMyAdmin it is 2 then why is it showing Old Value?

Please help! Thanks in advance.

Regards, Mike

Edit:

This is the code the OP tried:

mysql_connect("localhost","mayankx_tt","111111");
mysql_select_db("mayankx_tt") or die(mysql_error()); 
print_r(mysql_fetch_array(mysql_query("select visits from Orders")));
mysql_query("update Orders set visits=visits+1");
print_r(mysql_fetch_array(mysql_query("select visits from Orders"))); 

And his output:

Array ( [0] => 4 [visits] => 4 ) Array ( [0] => 4 [visits] => 4 )
  • 写回答

5条回答 默认 最新

  • dougezhua0017 2011-05-28 10:15
    关注

    Check you have write privileges to the database. Also check your query cache? Load up your db in either CLI or something like phpmyadmin / sequel pro and run the query as root. Check the results. The problem will most likely be down to permissions / caching.

    评论

报告相同问题?