2017-04-09 96 views
-2

此代碼給我和意外的文件結束。任何幫助?
即時通訊設法做一個sinmple頁面,它有許多不同的查詢。即時製作一頁,因爲它只是把東西放在一個地方,並節省時間。任何人有任何建議?文件意外結束,HTML PHP和MYSQL

<?php 
    $host="127.0.0.1"; 
    $username="root";  
    $pword=""; 
    $database="spm"; 

    require("db_connection.php"); 
    //for searching by customer name 
    $customername1 = $_POST['customername1']; 
    //variables for inserting new restaurant 
    $restname = $_POST['restname']; 
    $restaddress = $_POST['restaddress']; 
    $resthomephone = $_POST['resthomephone']; 
    $restcolpoints = $_POST['restcolpoints']; 
    $restdelpoints = $_POST['restdelpoints']; 

?> 

<html> 
    <head> 
     <title>Database search</title> 
    </head> 
    <body> 
<?php 
     $custidtosearch = ""; 
      $query_string = "SELECT custID FROM customertable WHERE custname ='".$customername1."'"; 
      if ($result = $mysqli -> query($query_string)) { 
       while ($row = $result -> fetch_object()) { 
        $custidtosearch = $row->dateid; 
       //echo $custidtosearch; 
       } 

      Echo "</table>"; 
      $result->close(); 
      }else{ 
       echo ("there was an error or there was no query"); 
      } 

      $query_string = "SELECT * FROM orderlist WHERE custid = '".$custidtosearch."'" ; 
      //echo $query_string; 
      if ($result = $mysqli -> query($query_string)) { 
       echo "<table border = '1'>"; 
       echo "<tr><th> Customer Name</th> <th>Order ID</th> <th>Customer ID</th> <th>Restaurant ID</th> <th>Order points</th> <th>Customer Points used</th></tr>"; 
       while ($row = $result -> fetch_object()) { 
        Echo "<tr>".$row->$customername1."</td>"; 
        Echo "<td>".$row->PersonID."</td>"; 
        Echo "<td>".$row->Name."</td>"; 
        Echo "<td>".$row->mobile."</td>"; 
        Echo "<td>".$row->email."</td>"; 
        Echo "<td>".$row->dateid."</td></tr>"; 
       } 
       Echo "</table>"; 
       $result->close(); 

        $query_string = "INSERT INTO `restauranttable`(`restname`, `address`, `phoneno`, `colpoints`, `delpoints`) VALUES ('".$restname."','".$restaddress."','".$resthomephone."', 
        '".$restcolpoints."','".$restdelpoints."')"; 
      if ($result = $mysqli -> query($query_string)) { 
       Echo ("Restaurant added"); 
      $result->close(); 
      }else{ 
       echo ("there was an error or there was no query"); 
      } 


     $mysqli->close(); 
?>  
     <p><a href=enterpageuni.php />Back</a></p> 
    </body> 
</html> 

回答

0

您的IF-STATEMENT缺少結束標籤。您需要檢查您的代碼以驗證結束標籤應放置在哪裏。

if ($result = $mysqli -> query($query_string)) { 
       echo "<table border = '1'>"; 
       echo "<tr><th> Customer Name</th> <th>Order ID</th> <th>Customer ID</th> <th>Restaurant ID</th> <th>Order points</th> <th>Customer Points used</th></tr>"; 
       while ($row = $result -> fetch_object()) { 
        Echo "<tr>".$row->$customername1."</td>"; 
        Echo "<td>".$row->PersonID."</td>"; 
        Echo "<td>".$row->Name."</td>"; 
        Echo "<td>".$row->mobile."</td>"; 
        Echo "<td>".$row->email."</td>"; 
        Echo "<td>".$row->dateid."</td></tr>"; 
       } 
       Echo "</table>"; 
       $result->close(); 
      } //<!--- I'm guessing this where the close tag should go. 
2

您錯過了一個代碼塊的關閉}。大概從第一個if ($result = $mysqli -> query($query_string)) {開始(在你打開<table>之前,文件的結尾是「意外的」,因爲PHP仍然在等待那個代碼塊被關閉。