我试图重新输入我的同学的代码,因为这里的'textarea'将受到大量字符串的轰炸,问题是请求URI太长。所以我尝试将所有$ _GET更改为$ _POST,因为它不会在URL中发布。
但问题是它不会在isset中显示输入'text'和'textarea'。我不知道这是问题或者是$ _POST,但是当我将它返回到$ _GET时它会起作用。
用于显示要更新的章节和更新功能的PHP代码。
<?php
if (isset($_POST['submit'])) {
$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'");
}
$result = $db->query("select * from chapter");
while($row = mysqli_fetch_assoc($result)) {
$update = 'chapterid';
echo "<li id='button' class='btn' ><b id='shadow'><a href='chapter1.php?update={$row['chapter_id']}'>{$row['chapter_title']}</b></a></li></button>";
}
?>
用于显示输入'text'和'textarea'的PHP代码。
<?php
if (isset($_POST['update'])) {
$update = $_POST['update'];
$result1 = $db->query("select * from chapter where chapter_id=$update");
while($row1 = mysqli_fetch_assoc($result1)) {
echo "<center>";
echo "<form class='form' method='POST'>";
echo "<h2>Update Form</h2>";
echo "<hr/>";
echo"<input class='input' type='hidden' name='cid' value='{$row1['chapter_id']}'/>";
echo "<br />";
echo "<label>" . "Chapter Title:" . "</label>" . "<br />";
echo"<input class='input' type='text' name='ctitle' value='{$row1['chapter_title']}' />";
echo "<br />";
echo "<label>" . "Chapter Body:" . "</label>" . "<br />";
echo "<textarea rows='15' cols='95' name='cbody'>{$row1['chapter_body']}";
echo "</textarea>";
echo "<br />";
echo "<input class='submit' type='submit' name='submit' value='update' />";
echo "</form>";
echo "</center>";
}
}
if (isset($_POST['submit'])) {
echo '<div class="form" id="form3"><br><br><br><br><br><br>
<Span>Data Updated Successfuly......!!</span></div>';
}
?>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
</div><?php
mysqli_close($db);
?>
答案 0 :(得分:2)
if (isset($_POST['update'])) {
此行应保留$ _GET [&#39; update&#39;],因为&#34;更新&#34;不属于你的形式,而是网址的一部分:
<a href='chapter1.php?update={$row['chapter_id']}'