我在将表单发布到数据库时遇到问题。第一部分是从一个表中检查 CustomerID 的查询,这部分工作正常。下一部分是将值发布到不同的表中。表格上一切正常,但没有发布到“订单”表,也没有返回任何错误。我错过了什么?
<?php
//Insert Into database
$mysqli = @ new mysqli('127.0.0.1','root',null,'storefront');
if (mysqli_connect_error())
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
$mysqli->select_db("storefront")
or die("<p>Unable to select the database.</p>"
."<p>Error code ". mysqli_errno($mysqli)
.": " . mysqli_error($mysqli)) . "</p>";
$customerid = isset($_POST['customerid']);
$custid = $_POST['customerid'];
if($customerid)
{
$result = $mysqli->query("SELECT * FROM customer WHERE customerID = '$custid'");
$row = $result->fetch_row();
if (!$row)
{
echo "Customer Number not found.".mysql_error();
exit;
}
}
else
{
$tableName = "orders";
$nullstr = "NULL";
$SQLstring = "INSERT INTO $tableName VALUES
('".$nullstr."','".$customerid."', '".$blue."','".$green."','".$red."')";
$result = $mysqli->query($SQLstring);
if ($result)
{
echo $mysqli->affected_rows ." $tableName database.<br />";
$mysqli->close();
}
}
?>