Mix form and mysql database query problems

I have the following view, which I reduced as much as possible without being sure where this problem comes from. I am trying to insert form values โ€‹โ€‹into a database.

However, when trying to use the form below, it spits out:

Request is empty

twice. The STATUS table exists as well as fields are dropped and noticed. The table currently contains no content. I don't understand why the query will be empty?

<?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\n". 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($userQuery)) {
        $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);
}

      

0


a source to share


3 answers


You appoint

$ statusQuery = "INSERT INTO ....



but you are referring to a variable named $ userQuery

if ($ statusInfo = $ conf> prepare ( $ userQuery )) {

0


a source


Is there a typo here:

$statusQuery = "INSERT INTO STATUS VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
if ($statusInfo = $con->prepare($userQuery)) {

      



Wouldn't the second line also have the statusQuery status?

0


a source


Try putting some content in the table ... It makes sense that if nothing is returned, it will tell you the query is empty.

0


a source







All Articles