| Member with 728 posts. THREAD STARTER | | Join Date: Jul 2005 Location: Norwich, UK | |
PHP increment help Could anyone help with this? The user hits a link which contains the $id and $action (the latter of which is 'increase' and calls this script). It is supposed to take marblecount, add 1 to it, and replace the original value with the new one.
However, if the beginning marblecount is 0, the new figure is not 1, as expected, but 2!
Why?
// Increase marble count
case "increase":
$sql = mysql_query("SELECT marblecount FROM marbles_collection WHERE id = '$id'") or die(mysql_error());
$row = mysql_fetch_array($sql);
extract($row);
$marblecount++;
$update = mysql_query("UPDATE marbles_collection SET marblecount = '$marblecount' WHERE id = '$id'") or die(mysql_error());
$redirect = "marbles_admin.php";
header("Refresh: 1.5; URL=$redirect");
include "includes/header.inc.php";
echo "<h3>Marbles Admin Page</h3>";
echo "<p>You have successfully made a marble available for reward.</p>";
echo "<p>You are now being redirected to the Marbles Admin Page...</p>";
include "includes/footer.inc.php";
break;
I tried doing it a different way and using this alternative (which is shorter):
case "increase":
$update = mysql_query("UPDATE marbles_collection SET marblecount = marblecount + 1 WHERE id = '$id'") or die(mysql_error());
$redirect = "marbles_admin.php";
header("Refresh: 1.5; URL=$redirect");
include "includes/header.inc.php";
echo "<h3>Marbles Admin Page</h3>";
echo "<p>You have successfully made a marble available for reward.</p>";
echo "<p>You are now being redirected to the Marbles Admin Page...</p>";
include "includes/footer.inc.php";
break;
But it still goes from 0 to 2! On subsequent runs it goes from 2 to 3, then 3 to 4, then 4 to 5, and so on (as it should!).
Last edited by DrP; 28-Nov-2006 at 04:52 PM..
|