我有一个购物车,我想将购买发送到我的数据库。我完全确定表单部分工作正常,但是需要将购买插入数据库的页面是错误的。但是,我真的不知道什么是错的,为什么它只给我一个空白页面(addorder.php,处理页面),而它应该在上一页给我一个错误信息。这是addorder.php的代码:
<?php
class PurchaseOrder
{
private $db_connection = null;
public $errors = array();
public $messages = array();
public function __construct()
{
if (isset($_POST["purchase"])) {
$this->addOrder();
}
}
private function addOrder()
{
if (empty($_POST['order_firstname'])) {
$this->errors[] = "Please fill in your first name.";
} elseif (empty($_POST['order_lastname'])) {
$this->errors[] = "Please fill in your last name.";
} elseif (empty($_POST['order_phone'])) {
$this->errors[] = "Please fill in your phone number.";
} elseif (empty($_POST['order_address'])) {
$this->errors[] = "Please fill in your address.";
} elseif (empty($_POST['order_city'])) {
$this->errors[] = "Please fill in your city.";
} elseif (empty($_POST['order_postalcode'])) {
$this->errors[] = "Please fill in your postal code.";
} elseif (empty($_POST['order_deliverydate'])) {
$this->errors[] = "Please fill in a delivery date you like.";
} elseif (empty($_POST['order_country'])) {
$this->errors[] = "Please choose your country.";
$this->db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (!$this->db_connection->set_charset("utf8")) {
$this->errors[] = $this->db_connection->error;
}
if (!$this->db_connection->connect_errno) {
$lastorder= "SELECT orderNumber FROM orders ORDER BY orderNumber DESC LIMIT 1";
$lastordernumber=mysql_query($lastorder);
while ($row=mysql_fetch_array($lastordernumber)) {
$lastnumber = $row['orderNumber'];
}
$order_firstname = $_POST['order_firstname'];
$order_lastname = $_POST['order_lastname'];
$order_phone = $_POST['order_phone'];
$order_address = $_POST['order_address'];
$order_city = $_POST['order_city'];
$order_postalcode = $_POST['order_postalcode'];
$order_deliverydate = $_POST['order_deliverydate'];
$order_country = $_POST['order_country'];
$order_date = date("Y-m-d");
$customernumber = $_SESSION['CustomerNumber'];
$sql = "INSERT INTO orders (orderNumber, orderDate, requiredDate, shippedDate, status, comments, customerNumber) VALUES('" . $lastnumber . "', '" . $order_date . "', null, null, null, null, '" . $customernumber . "');";
$query_new_order = $this->db_connection->query($sql);
if ($query_new_order) {
$this->messages[] = "Your profile has been updated succesfully!";
} else {
$this->errors[] = "Sorry, your registration failed. Please go back and try again.";
}
} else {
$this->errors[] = "Sorry, no database connection.";
}
} else {
$this->errors[] = "An unknown error occurred.";
}
}
}
这是我数据库中'orders'表的图片:
你们可以帮帮我,我调试了代码,没有语法错误。它能是什么?我现在很困惑......
编辑:这就是sendviaparcel.php页面上显示消息和错误的方式,也就是上面有表格的页面:
<?php
if (isset($purchaseOrder)) {
if ($purchaseOrder->errors) {
foreach ($purchaseOrder->errors as $error) {
echo '<div class="well"><h4><i class="fa fa-exclamation-triangle fa-3"></i> '.$error.'</h4></div>';
}
}
if ($purchaseOrder->messages) {
foreach ($purchaseOrder->messages as $message) {
echo '<div class="well"><h4><i class="fa fa-check fa-3"></i> '.$message.'</h4></div>';
}
}
}
require("includes/connection.php");
?>
这是sendviaparcel.php上的表格:
<form method="post" action="addorder.php" name="orderform">
<table class="table table-striped">
<---THIS IS MY TABLE CONTENT---/>
</table>
<a href="index.php" class="btn btn-login">Cancel <i class="fa fa-times fa-2"></i></a>
<button type="submit" class="btn btn-login btn-signin" name="purchase">Confirm purchase <i class="fa fa-check fa-2"></i></button>
</div>
</form>
我已经启用了错误报告,但它什么也没有返回。