What's new

J P

Journeyman
Joined
Jun 1, 2023
Posts
32
Reaction
0
Points
21
Need help! I encoded 4 drivers and 2 cars already, but it happens that after selecting Cars and Vehicle nothing is showing in the drop text (Available cars and Available drivers).
Please see photos and code below. Thank you!

PHP:
    <?php
        $connection= mysqli_connect("localhost","root","","vehicle management");
        session_start();
        
        $id= $_GET['id'];

        $sql= "SELECT * FROM `booking` WHERE booking_id='$id'";
        //echo $sql;
        $res= mysqli_query($connection,$sql);
        $row= mysqli_fetch_assoc($res);

        $sql1= "SELECT * FROM `vehicle` WHERE veh_available='0'";
        //echo $sql;
        $res1= mysqli_query($connection,$sql1);

        $sql2= "SELECT * FROM `driver` WHERE dr_available='0'";
        //echo $sql;
        $res2= mysqli_query($connection,$sql2);
    
    ?>


    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Confirm booking</title>
        
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
        <script src="https://code.jquery.com/jquery-2.2.0.min.js" type="text/javascript"></script>
        
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
    <?php include 'navbar_admin.php'; ?>
    <br>
    <div class="container">
        <div class="row">
            <div class="col-md-3"></div>
            <div class="col-md-6">
                <div class="page-header">
                    <h1 style="text-align:center;">Confirm Booking</h1>
                    <?php //echo $msg; ?>
                    </div>
                    
                    
                    
                    <p><strong>Booking Id: </strong><?php echo $row['booking_id']; ?></p>
                    
                
                    <p><strong>Customer Name: </strong><?php echo $row['name']; ?></p>
                    
                    
                    <p><strong>Requested Date: </strong><?php echo $row['req_date']; ?></p>
                    
                    
                    <p><strong>Requested Time: </strong><?php echo $row['req_time']; ?></p>
                    
                    
                    <p><strong>Return Date: </strong><?php echo $row['ret_date']; ?></p>
                    
                    
                    <p><strong>Return Time: </strong><?php echo $row['ret_time']; ?></p>
                    
                    
                    <p><strong>Destination: </strong><?php echo $row['destination']; ?></p>
                    
                    
                    <p><strong>PickUp Point: </strong><?php echo $row['pickup_point']; ?></p>
                    
                    
                    <p><strong>Email: </strong><?php echo $row['email']; ?></p>
                    
                    
                    <p><strong>Mobile: </strong><?php echo $row['mobile']; ?></p>
                    
                    
                    
                <form action="sendmail.php?id=<?php echo $id; ?>" method="post">
        
                        <div class="input-group">
                        <span class="input-group-addon"><b>Available Cars</b></span>
                            <select class="form-control" name="veh_reg";>
                            <?php
                                while($row1=mysqli_fetch_assoc($res1)) {  ?>
                                ?>
                                <option><?php echo $row1['veh_reg'];?></option>
                                <?php } ?>
                            </select>
                        </div>
                        <br>
                        <div class="input-group">
                        <span class="input-group-addon"><b>Available Drivers</b></span>
                            <select class="form-control" name="driverid">
                            <?php
                                while($row2=mysqli_fetch_assoc($res2)) {  ?>
                                ?>
                                <option><?php echo $row2['driverid']; ?></option>
                                <?php } ?>
                            </select>
                        </div>
                    
                        <br>
                        <button class="btn btn-success" type="submit" name="email">Confirm</button>
                    </form>
            </div>
            <div class="col-md-3"></div>
        </div>
    </div>
        
    </body>
    </html>
cg.JPG
 

Attachments

There doesn't seem to be any issue with your code. However, it's possible that the query results for the available cars and drivers are empty. To troubleshoot this issue, you can try the following steps:

1. Check if the database tables vehicle and driver have records with veh_available and dr_available set to 0, respectively.
2. Run the SQL queries $sql1 and $sql2 directly in your database management tool to see if they return any results.
3. Confirm that the database connection is successful by adding var_dump($connection); after the $connection variable is defined. This will display the current state of the connection.
4. Ensure that the database name, username, and password are correct in the mysqli_connect function.
5. Check if there are any errors being reported. You can add the following code at the top of your script to display any errors:

PHP:
error_reporting(E_ALL);
ini_set('display_errors', 1);

If none of these steps resolve the issue, please provide more details about the structure of your database tables and any error messages that you receive.
 
  • Like
Reactions: J P
There doesn't seem to be any issue with your code. However, it's possible that the query results for the available cars and drivers are empty. To troubleshoot this issue, you can try the following steps:

1. Check if the database tables vehicle and driver have records with veh_available and dr_available set to 0, respectively.
2. Run the SQL queries $sql1 and $sql2 directly in your database management tool to see if they return any results.
3. Confirm that the database connection is successful by adding var_dump($connection); after the $connection variable is defined. This will display the current state of the connection.
4. Ensure that the database name, username, and password are correct in the mysqli_connect function.
5. Check if there are any errors being reported. You can add the following code at the top of your script to display any errors:

PHP:
error_reporting(E_ALL);
ini_set('display_errors', 1);

If none of these steps resolve the issue, please provide more details about the structure of your database tables and any error messages that you receive.
1. Check if the database tables vehicle and driver have records with veh_available and dr_available set to 0, respectively.

This works! but can you help to code that everytime I used the vehicle/river, the value will return to 0.
 
1. Check if the database tables vehicle and driver have records with veh_available and dr_available set to 0, respectively.

This works! but can you help to code that everytime I used the vehicle/river, the value will return to 0.
To update the value of veh_available or dr_available to 0 every time a vehicle or driver is used, you can add an UPDATE query after selecting the available cars and drivers. Here's an updated version of your code that includes the necessary changes:

PHP:
<?php
$connection = mysqli_connect("localhost", "root", "", "vehicle management");
session_start();

$id = $_GET['id'];

$sql = "SELECT * FROM `booking` WHERE booking_id='$id'";
$res = mysqli_query($connection, $sql);
$row = mysqli_fetch_assoc($res);

$sql1 = "SELECT * FROM `vehicle` WHERE veh_available='0'";
$res1 = mysqli_query($connection, $sql1);

$sql2 = "SELECT * FROM `driver` WHERE dr_available='0'";
$res2 = mysqli_query($connection, $sql2);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Confirm booking</title>
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="https://code.jquery.com/jquery-2.2.0.min.js" type="text/javascript"></script>
    
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="style.css">
</head>
<body>
<?php include 'navbar_admin.php'; ?>
<br>
<div class="container">
    <div class="row">
        <div class="col-md-3"></div>
        <div class="col-md-6">
            <div class="page-header">
                <h1 style="text-align:center;">Confirm Booking</h1>
                <?php //echo $msg; ?>
            </div>
            
            <p><strong>Booking Id: </strong><?php echo $row['booking_id']; ?></p>
            <p><strong>Customer Name: </strong><?php echo $row['name']; ?></p>
            <p><strong>Requested Date: </strong><?php echo $row['req_date']; ?></p>
            <p><strong>Requested Time: </strong><?php echo $row['req_time']; ?></p>
            <p><strong>Return Date: </strong><?php echo $row['ret_date']; ?></p>
            <p><strong>Return Time: </strong><?php echo $row['ret_time']; ?></p>
            <p><strong>Destination: </strong><?php echo $row['destination']; ?></p>
            <p><strong>PickUp Point: </strong><?php echo $row['pickup_point']; ?></p>
            <p><strong>Email: </strong><?php echo $row['email']; ?></p>
            <p><strong>Mobile: </strong><?php echo $row['mobile']; ?></p>
            
            <form action="sendmail.php?id=<?php echo $id; ?>" method="post">
                <div class="input-group">
                    <span class="input-group-addon"><b>Available Cars</b></span>
                    <select class="form-control" name="veh_reg">
                        <?php
                        while ($row1 = mysqli_fetch_assoc($res1)) { ?>
                            <option><?php echo $row1['veh_reg']; ?></option>
                        <?php }
                        mysqli_query($connection, "UPDATE `vehicle` SET `veh_available` = '0' WHERE `veh_available` = '1'");
                        ?>
                    </select>
                </div>
                <br>
                <div class="input-group">
                    <span class="input-group-addon"><b>Available Drivers</b></span>
                    <select class="form-control" name="driverid">
                        <?php
                        while ($row2 = mysqli_fetch_assoc($res2)) { ?>
                            <option><?php echo $row2['driverid']; ?></option>
                        <?php }
                        mysqli_query($connection, "UPDATE `driver` SET `dr_available` = '0' WHERE `dr_available` = '1'");
                        ?>
                    </select>
                </div>
                
                <br>
                <button class="btn btn-success" type="submit" name="email">Confirm</button>
            </form>
        </div>
        <div class="col-md-3"></div>
    </div>
</div>

</body>
</html>

In this updated code, after fetching the available cars and drivers, an UPDATE query is executed to set the veh_available or dr_available column to 0 for the selected vehicle or driver. This way, the values will be updated in the database every time a vehicle or driver is used.
 

Similar threads

Back
Top