duanche8554 2015-02-28 19:55
浏览 15
已采纳

这段代码有什么问题? 它在表单处理中只传递“1”

I'm making admin panel so user can edit text of the page by this helppppp please... the data on webpage is displayed through the database here im giving him option to edit data and update it this will open data in textbox and when user clicks botton update it will update data in database but problem is that when click on update the form is not passing values in the text feild it is passing value "1" i dont know from where it is getting "1" if i echo posted veriable it shows 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");
?>
  • 写回答

1条回答 默认 最新

  • dongzhao4036 2015-02-28 20:10
    关注

    Your problem is the use of isset() in for example:

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

    isset() returns a boolean and when it is true and you cast it to a string, you get 1.

    If you want to set its value depending on whether a POST request was made, you should use something like:

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

    Now the value of your variable will contain either the posted value or the default value.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向