What's new

Updating data record PHP

J P

Journeyman
Joined
Jun 1, 2023
Posts
33
Reaction
0
Points
22
1714100904103.png
1714100944051.png

I have this error maybe I overlook something. I couldnt show the values from the data table on my edit form.
Im still learning. Thanks


PHP:
<?php
    if(!isset($_SESSION))
    {
        session_start();
    }
    $connection= mysqli_connect('localhost','root','','vehicle management');

    $id= $_SESSION['id'];
    
    $query= "SELECT * FROM `booking` WHERE booking_id ='$id'";
    $result= mysqli_query($connection,$query);
    $row= mysqli_fetch_assoc($result);
?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Booking</title>
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
     <link rel="stylesheet" href="css/wickedpicker.min.css">
    
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
     <link rel="stylesheet" href="sweetalert2/sweetalert2.css">
    <script src="sweetalert2/sweetalert2.min.js"></script>
    
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script src="js/wickedpicker.min.js"></script>
    <link rel="stylesheet" href="style.css">
</head>
<style>
    .navbar-fixed-top.scrolled {
   background-color: ghostwhite;
  transition: background-color 200ms linear;
}   
</style>

<body>
    <?php include 'navbar_admin.php'; ?>
    <br>
    <div class="container">
        <div class="row">
            <div class="page-header">
                <h1 style="text-align:center;">Update Booking</h1>
                 <?php //echo $msg; ?>
            </div>
            <div class="col-md-3"></div>
            <div class="col-md-6">
                <form class="animated bounce" action="bookingaction.php" method="post">
                  
                    <div class="input-group">
                      <span class="input-group-addon"><b>Name</b></span>
                      <input type="text" name = "name" id ="name"  class="form-control" value="<?php echo $row['name'];?>">
                    </div>
                    
                    <br>
                    <div class="input-group">
                      <span class="input-group-addon"><b>Department</b></span>
                      <input id="department" type="text" class="form-control" name="department"  value="<?php echo $row['department'];?>">
                    </div>
                    <br>
                    <div class="input-group">
                      <span class="input-group-addon"><b>Vehicle Type</b></span> &nbsp;
                      <label><input type="radio" name="type" value="car">Car</label> &nbsp;
                      <label><input type="radio" name="type" value="van">Van</label>
                    </div>
                    <br>
                    <div class="input-group">
                      <span class="input-group-addon"><b>Date of Requirement</b></span>
                      <input id="req_date" type="text" class="form-control" name="req_date" placeholder="Day the car is needed" required>
                      <input type="text" name="req_time" id="req_time" class="form-control"/>
                      
                    </div>
                    
                    <script>
                      $( function() {
                        $( "#req_date" ).datepicker();
                        $("#req_time").wickedpicker();
                        
                      } );
                        
                        
                        
                    </script>
                    <br>
                    
                    <div class="input-group">
                      <span class="input-group-addon"><b>Date of Return</b></span>
                      <input id="return_date" type="text" class="form-control" name="return_date" placeholder="Day the car will return" required>
                      <input type="text" name="return_time" id="return_time" class="form-control"/>
                    </div>
                    
                    <script>
                      $( function() {
                        $( "#return_date" ).datepicker();
                        $( "#return_time" ).wickedpicker();
                      } );
                    </script>
                    <br>
                    
                    <div class="input-group">
                      <span class="input-group-addon"><b>Destination</b></span>
                      <input id="destination" type="text" class="form-control" name="destination" placeholder="Car Destination" required>
                    </div>
                    <br>
                    
                    <div class="input-group">
                      <span class="input-group-addon"><b>Pickup Point</b></span>
                      <input id="pickup" type="text" class="form-control" name="pickup" placeholder="pickup">
                    </div>
                    <br>
                    
                    <div class="input-group">
                      <span class="input-group-addon"><b>Reason for booking</b></span>
                      <input id="reason" type="text" class="form-control" name="reason" placeholder="Reason of booking the vehicle">
                    </div>
                    <br>
                    
                    <div class="input-group">
                      <span class="input-group-addon"><b>Email</b></span>
                      <input id="email" type="email" class="form-control" name="email" value="<?php echo $row['email']; ?>">
                    </div>
                    <br>
                    
                    <div class="input-group">
                      <span class="input-group-addon"><b>Mobile</b></span>
                      <input id="mobile" type="text" class="form-control" name="mobile" value="<?php echo $row['unumber']; ?>">
                    </div>
                    <br>
                    
                    <input type="hidden" name="username" value="<?php echo $username; ?>">
                    
                    <div class="input-group">
                        <input type="submit" name="submit" class="btn btn-success">
                    </div>
                    
                    
                </form>
            </div>
            <div class="col-md-3"></div>
        </div>
    </div>
    
<script>
    $(function () {
  $(document).scroll(function () {
    var $nav = $(".navbar-fixed-top");
    $a= $(".navbar-fixed-top");
    $nav.toggleClass('scrolled', $(this).scrollTop() > $a.height());
  });
});
    
</script> 
</body>
</html>
 

Attachments

It looks like you are trying to retrieve data from the database and populate a form with the values for editing. However, there are a few things that might be causing the issue. Here are some suggestions to help you troubleshoot:

1. Check Session Variable: Ensure that the $_SESSION['id'] is set correctly and contains the ID you are expecting. You can add a debug statement to check if the ID is correct:

PHP:
$id = isset($_SESSION['id']) ? $_SESSION['id'] : null;
echo "ID from session: $id"; // Add this line to check the ID

2. Check Database Connection: Verify that your database connection is successful. You can add a check to see if the connection is established:

PHP:
if (!$connection) {
    die("Connection failed: " . mysqli_connect_error());
}

3. Check Query Execution: Make sure that your SQL query is correct and that it returns results. You can add a check to see if the query is executed successfully:

PHP:
if (!$result) {
    die("Query failed: " . mysqli_error($connection));
}

4. Check Data Retrieval: After fetching the row from the database, check if it contains the data you expect. You can print the $row variable to see the retrieved data:

PHP:
var_dump($row); // Add this line to check the fetched data

5. Check Input Fields: Verify that the column names in your database table (name, department, email, unumber, etc.) match the keys you are using to access the data in the $row array.

By adding these debug statements and checks, you should be able to identify where the issue lies and fix it accordingly. Let me know if you need further assistance!
 
fix muna yung href papuntang update booking
ganito ata, href="trip_edit.php?id=<?php echo $row['booking_id'] ?>

if okay na yun

change mo yung $id= $_SESSION['id'];
to $id= $_GET['id']; -> meaning kinukuha mo yung id na nasa url. Example kung ini edit mo yung row ng may booking_id na 77. So your variable $id will be equal to 77. But i dont know maybe sa session id mo inistore yung data.

and for making sure the data is right, i var_dump() mo yung mga data mo.
example var_dump($id)
check mo kung 77 ba, or tama ba yung data na nakuha mo or yung in-expect mong data. Check mo rin data ng $row mo.
 

Similar threads

Back
Top