PHP提交页面完全空白

时间:2015-05-19 18:47:19

标签: php html sql database

我通过表单提交购买(我称之为订单)。我完全确定这部分工作正常,但是购买需要插入数据库的页面是错误的。但是,我并不是真的知道什么是错的,为什么它只给我一个空白页面(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.";
        }
    }
}

这是“订单”的图片。我的数据库中的表: enter image description here

你们可以帮帮我,我调试了代码,没有语法错误。它能是什么?我现在很困惑......

编辑:这就是sendviaparcel.php页面上显示消息和错误的方式,也就是上面有表格的页面:

&#13;
&#13;
<?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");
	
?>
&#13;
&#13;
&#13;

这是sendviaparcel.php上的表格:

&#13;
&#13;
<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>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

空白页通常是由于缺少行终结符;而导致的......或者在您的情况下,可能太多了?

$sql = "INSERT INTO orders (orderNumber, orderDate, requiredDate, shippedDate, status, comments, customerNumber) VALUES('" . $lastnumber . "', '" . $order_date . "', null, null, null, null, '" . $customernumber . "');";

在SQL语句结束时,你有一个不必要的;,这可能是你的代码搞乱了。

应为$customernumber . "')";