我有一個簡單的表單和一個MySQL表設置。增加基於PHP表單提交的MySQL行值
所有我試圖做的是每一個表單提交加1到選定行時間量。
表是非常簡單:
answer | amount
------------------------
Yes | 5
No | 12
Maybe | 1
而且形式是:
<form action="submit.php" method="post">
Is this a cool pie chart?:
<input type="radio" name="group1" value="Yes"> Yes<br>
<input type="radio" name="group1" value="No"> No<br>
<input type="radio" name="group1" value="Maybe"> Maybe<br>
<input type="submit">
</form>
然後在submit.php我見到目前爲止以下,但似乎並不奏效
<?php
$sql = "UPDATE results SET amount= amount + 1 where answer = ?";
$stmt = mysqli_prepare($conn, $sql);
mysqli_stmt_bind_param($stmt, "s", $selected_option);
if (isset($_POST['submit'])) {
$selected_option = $_POST['group1'];
if ($selected_option == 'Yes') {
mysqli_stmt_execute($stmt);
}else if ($selected_option == 'No') {
mysqli_stmt_execute($stmt);
} else if ($selected_option == 'Maybe')
mysqli_stmt_execute($stmt);
}
?>
所以,如果有人回答是的金額是肯定會增加到6等等等
我已成功地調用數據,甚至將其添加到使用教程谷歌可視化API,但似乎在這個部分失敗。
在此先感謝大家。
我們能看到你的'submit.php'代碼? – Gavin
你想要一個MySQL查詢? –
我做了一個編輯以包括submit.php到目前爲止的代碼,甚至不知道如果我在正確的道路上:/ –