note 58712 added to function.mysql-query
| From: | gunniboyh at web dot de | Date: | Sun, 13 Nov 2005 15:13:50 +0000 |
| Subject: | note 58712 added to function.mysql-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-98509@lists.php.net to get a copy of this message | ||
With PHP 4.3.6. (thats what i'm using) you should never use $var++ within a mysql-query.
eg:
<?php
$link=mysql_connect("HOST","USER","PASSWORD");
mysql_select_db("mydatabase");
$var=1;
mysql_query("UPDATE mytable SET mynumber=".$var++.";");
echo $var;
mysql_close($link);
?>
When opening this site with your browser, you get:
2
Seems to be all right. But if you select it later from your database, you will see that it's 1.
However, increasing it first and then sending the mysql-query solves the problem.
----
Manual Page -- http://www.php.net/manual/en/function.mysql-query.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+58712
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58712&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58712&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58712&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58712&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58712&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58712&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58712&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+58712&report=yes
Search -- http://master.php.net/manage/user-notes.php