-2

This code is giving me and unexpected end of file. any help?
im trying to make a sinmple page that has many different queries on it. im making one page as it just keeps things in one place and to save time. anyone got any recommendations?

 <?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> 
cosmoonot
  • 2,161
  • 3
  • 32
  • 38

2 Answers2

2

You're missing a closing } for one of your code blocks. Probably from the first if ($result = $mysqli -> query($query_string)) { (before you open the <table>. The end of file is "unexpected" because PHP is still waiting for that code block to be closed.

rickdenhaan
  • 10,857
  • 28
  • 37
0

Your IF-STATEMENT is missing a closing tag. You need to check your code to verify where the closing tag should be placed.

 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.
cosmoonot
  • 2,161
  • 3
  • 32
  • 38