2017-04-09 80 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仍然在等待那个代码块被关闭。