这个代码出了什么问题?它正在通过“;1〃;在表单处理中


What is wrong with this code? It is passing just "1" in the form handling

我正在制作管理面板,这样用户就可以通过这个帮助pppp编辑页面的文本了,请。。。网页上的数据是通过这里的数据库显示的,我给了他编辑数据和更新数据的选项,这将在文本框中打开数据,当用户点击botton更新时,它将更新数据库中的数据,但问题是,当点击更新时,表单没有在文本中传递值,而是在传递值"1"

<?php
$query2 = mysqli_query($con, "SELECT * FROM home");
$row    = mysqli_fetch_array($query2);    
$pic1 = ucfirst($row['pic1']);
$pic2 = ucfirst($row['pic2']);
$pic3 = ucfirst($row['pic3']);
$pic4 = ucfirst($row['pic4']);
$pic5 = ucfirst($row['pic5']);
$pic6 = ucfirst($row['pic6']);
$pic7 = ucfirst($row['pic7']);
$pic8 = ucfirst($row['pic8']);
$par1 = ucfirst($row['par1']);
$par1pic = ucfirst($row['par1pic']);
$par2 = ucfirst($row['par2']);
$side_pic1 = ucfirst($row['side_pic1']);
$side_pic2 = ucfirst($row['side_pic2']);
?>
<form method="POST" action="update_home.php">
    Paragraph no 1:
    <textarea name="comment" rows="5" cols="40"><?php echo $par1; ?></textarea>
    First name:
    <input type="text" name="fname"><br>
    <input type="submit" name="nw_update" value="Update_1"/><br><br>
</form>
<form method="POST" action="update_home.php">
    Paragraph no 2:
    <textarea name="comment1" rows="5" cols="40"><?php echo $par2; ?></textarea>
    enter code here
    <input type="submit" name="nw_update" value="Update_2"/><br><br>
</form>

<?php
include("dbconnection.php");
$value = isset($_POST["nw_update"]);
$fname = isset($_POST["fname"]);
echo $fname;
echo $value;
if ($value == "Update_1") {
    $par = isset($_POST["comment"]);
    $query2 = mysqli_query($con, "UPDATE home SET par1='$par' where id='1'");
}
if ($value == "Update_2") {
    $par2 = isset($_POST["comment1"]);
    $query2 = mysqli_query($con, "UPDATE home SET par2='$par2' where id='1'");
}
header("location : edit_home.php");
?>

您的问题是在例如:中使用isset()

$value = isset($_POST["nw_update"]);

isset()返回一个布尔值,当它是true并将其强制转换为字符串时,得到1

如果你想根据是否发出POST请求来设置它的值,你应该使用这样的东西:

$value = isset($_POST["nw_update"]) ?  $_POST["nw_update"] : 'default value (can be an empty string or NULL or something from the database)';

现在,变量的值将包含已发布的值或默认值。