1

How do i display data from two tables while running the code below. I have a table called PASSENGERS and I would like to select a fname from that table and add it so as to display it also within output html table.I get and error Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, bool given in C:\xampp\htdocs\aero\view_booked_tickets.php on line 63 everytime i try to query two table.

 <?php
        session_start();
    ?>
    <html>
        <head>
            <title>
                View Booked Tickets
            </title>
            <style>
                input {
                    border: 1.5px solid #030337;
                    border-radius: 4px;
                    padding: 7px 30px;
                }
                input[type=submit] {
                    background-color: #030337;
                    color: white;
                    border-radius: 4px;
                    padding: 7px 45px;
                    margin: 0px 390px
                }
                table {
                 border-collapse: collapse; 
                 margin-left: 10%;
                 margin-right: 10%;
                }
                tr/*:nth-child(3)*/ {
                 border: solid thin;
                }
                .set_nice_size{
                    font-size: 17pt;
                }
            </style>
            <link rel="stylesheet" type="text/css" href="css/style.css"/>
            <link rel="stylesheet" href="font-awesome-4.7.0\css\font-awesome.min.css">
        </head>
        <body>
            <img class="logo" src="images/shutterstock_22.jpg"/> 
            <h1 id="title">
                AADITH AIRLINES
            </h1>
            <div>
                <ul>
                    <li><a href="customer_homepage.php"><i class="fa fa-home" aria-hidden="true"></i> Home</a></li>
                    <li><a href="customer_homepage.php"><i class="fa fa-desktop" aria-hidden="true"></i> Dashboard</a></li>
                    <li><a href="home_page.php"><i class="fa fa-plane" aria-hidden="true"></i> About Us</a></li>
                    <li><a href="home_page.php"><i class="fa fa-phone" aria-hidden="true"></i> Contact Us</a></li>
                    <li><a href="logout_handler.php"><i class="fa fa-sign-out" aria-hidden="true"></i> Logout</a></li>
                </ul>
            </div>
            <h2>VIEW BOOKED FLIGHT TICKETS</h2>
            <h3 class='set_nice_size'><center><u>Upcoming Trips</u></center></h3>
            <?php
                $todays_date=date('Y-m-d');
                $thirty_days_before_date=date_create(date('Y-m-d'));
                date_sub($thirty_days_before_date,date_interval_create_from_date_string("30 days")); 
                $thirty_days_before_date=date_format($thirty_days_before_date,"Y-m-d");
                
                $customer_id=$_SESSION['login_user'];
                require_once('Database Connection file/mysqli_connect.php');
                $query="SELECT pnr,date_of_reservation,flight_no,journey_date,class,booking_status,no_of_passengers,payment_id FROM Ticket_Details where customer_id=? AND journey_date>=? AND booking_status='CONFIRMED' ORDER BY  journey_date";
                $stmt=mysqli_prepare($dbc,$query);
                mysqli_stmt_bind_param($stmt,"ss",$customer_id,$todays_date);
                mysqli_stmt_execute($stmt);
                mysqli_stmt_bind_result($stmt,$pnr,$date_of_reservation,$flight_no,$journey_date,$class,$booking_status,$no_of_passengers,$payment_id);
                mysqli_stmt_store_result($stmt);
                if(mysqli_stmt_num_rows($stmt)==0)
                {
                    echo "<h3><center>No upcoming trips!</center></h3>";
                }
                else
                {
                    echo "<table cellpadding=\"10\"";
                    echo "<tr><th>PNR</th>
                    <th>Date of Reservation</th>
                    <th>Flight No.</th>
                    <th>Journey Date</th>
                    <th>Class</th>
                    <th>Booking Status</th>
                    <th>No. of Passengers</th>
                    <th>Payment ID</th>
                    </tr>";
                    while(mysqli_stmt_fetch($stmt)) {
                        echo "<tr>
                        <td>".$pnr."</td>
                        <td>".$date_of_reservation."</td>
                        <td>".$flight_no."</td>
                        <td>".$journey_date."</td>
                        <td>".$class."</td>
                        <td>".$booking_status."</td>
                        <td>".$no_of_passengers."</td>
                        <td>".$payment_id."</td>
                        </tr>";
                    }
                    echo "</table> <br>";
                }
                echo "<br><h3 class=\"set_nice_size\"><center><u>Completed Trips</u></center></h3>";
    
                $query="SELECT pnr,date_of_reservation,flight_no,journey_date,class,booking_status,no_of_passengers,payment_id FROM Ticket_Details where customer_id=? and journey_date<? and journey_date>=? ORDER BY  journey_date";
                $stmt=mysqli_prepare($dbc,$query);
                mysqli_stmt_bind_param($stmt,"sss",$customer_id,$todays_date,$thirty_days_before_date);
                mysqli_stmt_execute($stmt);
                mysqli_stmt_bind_result($stmt,$pnr,$date_of_reservation,$flight_no,$journey_date,$class,$booking_status,$no_of_passengers,$payment_id);
                mysqli_stmt_store_result($stmt);
                if(mysqli_stmt_num_rows($stmt)==0)
                {
                    echo "<h3><center>No trips completed in the past 30 days!</center></h3>";
                }
                else
                {
                    echo "<table cellpadding=\"10\"";
                    echo "<tr><th>PNR</th>
                    <th>Date of Reservation</th>
                    <th>Flight No.</th>
                    <th>Journey Date</th>
                    <th>Class</th>
                    <th>Booking Status</th>
                    <th>No. of Passengers</th>
                    <th>Payment ID</th>
                    </tr>";
                    while(mysqli_stmt_fetch($stmt)) {
                        echo "<tr>
                        <td>".$pnr."</td>
                        <td>".$date_of_reservation."</td>
                        <td>".$flight_no."</td>
                        <td>".$journey_date."</td>
                        <td>".$class."</td>
                        <td>".$booking_status."</td>
                        <td>".$no_of_passengers."</td>
                        <td>".$payment_id."</td>
                        </tr>";
                    }
                    echo "</table> <br>";
                }
                mysqli_stmt_close($stmt);
                mysqli_close($dbc);
            ?>
        </body>
    </html>
Oriba
  • 11
  • 2
  • 1
    Note: The [object-oriented interface to `mysqli`](https://www.php.net/manual/en/mysqli.quickstart.connections.php) is significantly less verbose, making code easier to read and audit, and is not easily confused with the obsolete `mysql_query` interface where missing a single `i` can cause trouble. Example: `$db = new mysqli(…)` and `$db->prepare("…")` The procedural interface is an artifact from the PHP 4 era and should not be used in new code. Additionally the procedural interface has less rigorous error checking and reporting, frustrating debugging efforts. – tadman Oct 30 '20 at 21:30
  • 1
    "Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, bool given" is the absolutely single most asked PHP question here. **Check your credentials and ensure that the connection is successful before using it.** – tadman Oct 30 '20 at 21:31
  • 1
    Tip: A lot of problems can be detected and resolved by [enabling exceptions in `mysqli`](https://stackoverflow.com/questions/14578243/turning-query-errors-to-exceptions-in-mysqli) so errors resulting from simple mistakes made aren’t easily ignored. Without exceptions you must pay close attention to return values, many of these indicate problems you must resolve or report to the user. Exceptions allow for more sophisticated flow control as they can “bubble up” to other parts of your code where it’s more convenient to handle them. – tadman Oct 30 '20 at 21:32

0 Answers0