PHP提交页面完全空白
我通过表单提交购买(我称之为订单)。我完全相信这部分工作正常,但是需要将购买插入数据库的页面是错误的。然而,我真的不知道哪里出了问题,为什么它只给我一个空白页面(addorder.php,处理页面),而它应该在上一页给我一条错误消息。以下是addorder.php的代码:PHP提交页面完全空白,php,html,sql,database,Php,Html,Sql,Database,我通过表单提交购买(我称之为订单)。我完全相信这部分工作正常,但是需要将购买插入数据库的页面是错误的。然而,我真的不知道哪里出了问题,为什么它只给我一个空白页面(addorder.php,处理页面),而它应该在上一页给我一条错误消息。以下是addorder.php的代码: <?php class PurchaseOrder { private $db_connection = null; public $errors = array(); public $me
<?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.";
}
}
}
空白页最常见的原因是缺少行终止符代码>。。。或者对你来说,可能太多了
$sql=“插入订单(订单号、订单日期、需求日期、发货日期、状态、注释、客户编号)值(“$lastnumber.”、“$order_date.”、null、null、null、“$customerNumber.”)代码>
在SQL语句的末尾,您有一个不必要的代码>这可能就是你的代码被弄乱的原因
它应该是$customernumber。"')";代码>打开文件后立即将错误报告添加到文件顶部^yep,空白页检查器^authorized userecho?!回声?-我没有听到回声。你喜欢山姆吗@Jayblanchard为什么要使用while
循环来读取限制为1的查询的结果?^被这么多Ralph错过了!我应该更仔细地看一下@Fred ii,SQL查询允许以结尾代码>即使这是问题所在,为什么会导致空白页?SQL语法错误不会导致PHP脚本失败query()
发生这种情况时只返回false
。它仍然不起作用,但我编辑了我的帖子。你能告诉我怎么了吗?