views:

84

answers:

3

I have the following form, which I have reduced as much as I can, without being sure where the problem is coming from. I am trying to insert the form values into a database.

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

Query was empty

twice. The STATUS table exists, as do the fields deleted and notice. The table is currently empty of content. I don't understand why the query would 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);
}
A: 

Is there a typo here:

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

Shoudn't the second line be $statusQuery also?

gacrux
A: 

Try putting some content into the table... It makes sense that if there is nothing to return it would tell you that the query was empty.

Josh Curren
A: 

You assignment is

$statusQuery = "INSERT INTO....

but you reference a variable named $userQuery

if ($statusInfo = $con->prepare($userQuery)) {

Hannes de Jager