我真的很難打破這個堅果。準備好的語句返回undefined索引錯誤
MySQL數據庫由以下列名組成:。
我在窗體中有一個按鈕。當我點擊「選擇」按鈕時,列名records
應該更新爲+1。每次我按一下按鈕我得到的錯誤:
Notice: Undefined index: id in /Applications/MAMP/htdocs/practiceProject/updaterecords.php on line 8 Updated Succesfull
我在計算器上閱讀,這是因爲我沒有得到id的值。所以我加了$id = $_POST['id'];
,但仍然得到相同的錯誤。
有沒有人知道這裏有什麼問題?
的index.php
<form action="updaterecords.php" method="post">
<button type="submit" name="selectstore" >Select</button>
<?php include 'updaterecords.php' ?>
<button type="button" data-dismiss="modal">Close</button>
</form>
updaterecords.php
<?php error_reporting(E_ALL); ini_set('display_errors', 1);
if (mysqli_connect_errno()) { echo "Error: no connexion allowed : " . mysqli_connect_error($mysqli); }
?>
<?php
include 'dbconnection.php';
if(isset($_POST['selectstore'])) {
$id = $_POST['id']; // Line 8
$stmt = $mysqli->prepare("UPDATE stores SET records = records + 1 WHERE id= ?");
$stmt->bind_param('i', $id);
if ($stmt->execute()) {
$success = true;
}
$stmt->close();
$mysqli->close();
if($success) {
echo "Updated Succesfull";
} else {
echo "Failed: " . $stmt->error;
}
}
?>
你的表單是否帶有'name =「id」'的字段?如果它不'$ _POST ['id']'永遠不會被填充。 –
感謝您的評論。我在這個問題上的表單,或者當我插入數據,或? – NMkdk4
上面顯示的表單沒有名爲'id'的輸入,所以'$ _POST ['id']'沒有設置。爲什麼你在表單中間包含一個文件? –