我有一個代碼不會更新。如果我在輸入文本中輸入任何內容並按下提交,那麼'samp.php'仍將顯示我已更新的數據庫的原始信息。PHP不會更新Mysql
代碼的index.php爲connect.php
<?php
include 'connect.php';
?>
<html>
<head>
<title>Basic Form Handling PHP</title>
</head>
<body>
<?php
$result1 = $db->query("select * from chapter where chapter_id='1'");
while($row1 = mysqli_fetch_assoc($result1)){ echo "<form action='samp.php' method='POST'>";
echo " <input class='input' type='hidden' name='cid' value='{$row1['chapter_id']}'/>";
echo " Title: <br>";
echo " <input type='text' name='ctitle'><br>";
echo " Body: <br>";
echo " <input type='text' name='cbody'><br>";
echo " <input type='submit' name='submit' value='PRESS ME'>";
echo " </form>";
}
?>
</body>
</html>
代碼samp.php
<?php
$db = new mysqli('localhost', 'root', '2830775', 'unity');
?>
碼
<?php
include 'connect.php';
?>
<?php
$id = $_POST['cid'];
$title = $_POST['ctitle'];
$body = $_POST['cbody'];
$result = $db->query("UPDATE chapter set chapter_title='$title', chapter_body='$body' where chapter_id='$id");
$result2 = $db->query("SELECT * FROM chapter where chapter_id='$id'");
?>
<?php $row1 = mysqli_fetch_assoc($result2);
echo $row1['chapter_body'];
?>
看來你沒有'include'connect.php';'在samp.php – KAD