0

ok so I have a table called voting with 3 columns (idnum, name, numvotes). I created radio buttons in an array based on the number of rows in this table, all with the same name (name="preference") I need to update the numvotes field ( add 1) depending on the radio button selected. Cant seem to get this working with the following code...

<?php
$uquery = "update voting set numvotes='". ($_POST['preference'] + 1) ."' where idnum=" .$_POST['idnum'];
$uresults = mysql_query( $uquery);
?>
4

1 回答 1

0

您在 $_POST['preference'] 返回的值上加 1,而不是在数据库中的值上加 1。由于单引号,您还将值设置为字符串,而不是数字。

假设 $_POST['preference'] 是当前投票数:

$uquery = "update voting set numvotes=". ($_POST['preference'] + 1) ." where idnum=".$_POST['idnum'];
于 2013-11-11T21:05:52.333 回答