http://stackoverflow.com/questions/5846/add-1-to-a-field
Didn't really work.
My script looks as follows:
<?php
if (isset($_GET["id"]) && isset($_GET["char"])) {
$id = $_GET["id"];
$char = $_GET["char"];
$result = mysql_query("SELECT * FROM battles WHERE id='$id'");
if ($char == "1") {
$bool = "first_char_votecount";
while($row = mysql_fetch_array($result)) {
$mincemeat = 1 + $row["first_char_votecount"];
}
}
elseif ($char == "2") {
$bool = "second_char_votecount";
$row = mysql_fetch_array($result);
$mincemeat = 1 + $row["second_char_votecount"];
}
}
mysql_query("UPDATE battles SET $bool = $mincemeat WHERE id = $id");
?>
At ?id=34&char=1
. The query should go from UPDATE battles SET $bool = $mincemeat WHERE id = $id"
to UPDATE battles SET first_char_votecount = 2 WHERE id = 34"
. Instead, I get this:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in ===\XAMPP\htdocs\vote.php on line 12
Notice: Undefined variable: mincemeat in ===\XAMPP\htdocs\vote.php on line 23