douweng3383 2009-05-15 13:13
浏览 24

以php形式传递变量的问题

I have the following php form.

I am trying to make it so that when the form is loaded, the values will be assigned the appropriate check- variable. This variable will contain either "checked or "". If it contains checked, the way it is displayed with the html should cause the relevant checkbox to be checked.

As it is, the variables do not seem to be being passed. When I echo out $deleted or $notice from within the submitinfo branch, they are blank. Furthermore, nothing is being inserted into the database, and I am not getting any database error. How can I check this?

<?php
if (isset($_GET["cmd"]))
  $cmd = $_GET["cmd"]; else
if (isset($_POST["cmd"]))
  $cmd = $_POST["cmd"]; else
die("Invalid URL");
if (isset($_GET["pk"])) {
    $pk = $_GET["pk"];
}
if (isset($_POST["deleted"])) {
    $deleted = $_POST["deleted"];
}
if (isset($_POST["notice"])) {
    $notice = $_POST["notice"];
}
$con = mysqli_connect("localhost","user","password", "db");
if (!$con) {
    echo "Can't connect to MySQL Server. Errorcode: %s
". mysqli_connect_error();
    exit;
}
$con->set_charset("utf8");
$getformdata = $con->query("select * from STATUS where ARTICLE_NO = '$pk'");
$checkDeleted = "";
$checkNotice = "";
while ($row = mysqli_fetch_assoc($getformdata)) {
    $checkDeleted = $row['deleted'];
    $checkNotice = $row['notice'];
}
if($cmd=="submitinfo") {
    $statusQuery = "INSERT INTO STATUS VALUES (?, ?)";
    if ($statusInfo = $con->prepare($statusQuery)) {
        $statusInfo->bind_param("ss", $deleted, $notice);
        $statusInfo->execute();
        $statusInfo->close();
        echo "true";
    } else {
        echo "false";
    }
    print_r($con->error);
}
if($cmd=="EditStatusData") {
    echo "<form name=\"statusForm\" action=\"test.php\" method=\"post\" enctype=\"multipart/form-data\">
<h1>Editing information for auction: ".$pk."</h1>
Löschung Ebay:
<input type=\"checkbox\" name=\"deleted\" value=\"checked\" ".$checkDeleted." />
<br />
Abmahnung:
<input type=\"checkbox\" name=\"notice\"  value=\"checked\" ".$checkNotice."  />
<br />
<input type=\"hidden\" name=\"cmd\" value=\"submitinfo\" />
<input name=\"Submit\" type=\"submit\" value=\"submit\" />
</form>";
} else {
    print_r($con->error);
}
  • 写回答

4条回答 默认 最新

  • duanjue6584 2009-05-15 13:19
    关注

    About checking the errors check the web server logs or make sure php is displaying errors in your php.ini.

    Are you POSTing to the web page? $deleted and $notice will only be set on POST requests.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题