Plus one to mysql value problem
I have a problem.
<?php
if (isset($_GET['id']))
{
$_GET['id'] = intval($_GET['id']);
$query = mysql_query("SELECT * FROM `banners` WHERE `id` = '" . $_GET['id'] . "'");
if (mysql_num_rows($query))
{
$row = mysql_fetch_array($query);
if ($row['views'] <= $row['ordered'])
{
if (empty($_GET['p']))
{
mysql_query("UPDATE `banners` SET `views` = `views` + 1 WHERE `id` = '" . $_GET['id'] . "'");
}
header('Cont开发者_运维技巧ent-type: '. $row['mime']);
echo $row['image'];
}
}
}
script.php?id=1&p=
The value views
is changed to "plus two", and not plus one.
Now 14, after 16.
EDIT:
If I commented
header('Content-type: '. $row['mime']);
echo $row['image'];
It's good. Where is the problem?
UPD 2:
F5 -> Page loaded 2 times..
1: - Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
2: Accept=image/png,image/*;q=0.8,*/*;q=0.5
WTF?
As @Shakti Singh said, it's executed twice. If you have access to access.log on your server, look into it and you'll see that. If not, try to log access to your database.
Or, you have same code somewhere else and is executed, too
精彩评论