我通过表单提交购买(我称之为订单)。我完全确信这部分工作正常,但购买需要插入数据库的页面是错误的。但是,我真的不知道什么是错的,为什么它只给了我一个空白页面(addorder.php,处理页面),而它应该给我在前一页上的错误消息。这是addorder.php代码: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.";
}
}
}
这是我的数据库中的“订单”表中的照片:
你们能帮助我吗,我调试的代码,并有没有语法错误。它会是什么?我很困惑,现在...
编辑:这是怎样的消息和错误显示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>';
}
}
}
\t \t
\t require("includes/connection.php");
\t
?>
这是sendviaparcel.php形式:
<form method="post" action="addorder.php" name="orderform">
\t \t <table class="table table-striped">
<---THIS IS MY TABLE CONTENT---/>
\t \t </table>
\t <a href="index.php" class="btn btn-login">Cancel <i class="fa fa-times fa-2"></i></a>
\t <button type="submit" class="btn btn-login btn-signin" name="purchase">Confirm purchase <i class="fa fa-check fa-2"></i></button>
</div>
</form>
添加错误报告给您的文件(S)的顶部您开'
^yep,空白页面检查器^ *授权用户* –
'addorder.php'中没有'echo'语句,你为什么期望看到什么? – Barmar