0

This is the code to submit the form and store it in the database I want to show the form details in another page after submitting

if(isset($_POST['submit']))
{
    $pickup = $_POST['pickup'];
    $dropoff = $_POST['dropoff'];
    $from_date = $_POST['fromdate'];
    $to_date = $_POST['todate'];
    $diff = date_diff($from_date, $to_date);
    //$difff = $diff->format("%a"). " Days ";


    if($from_date < $to_date)
    {
        //$_SESSION['diff'] = $diff->format("a%");
        //Create SQL Query
        $sql = "INSERT INTO search SET
        pickup='$pickup',
        dropoff='$dropoff',
        from_date='$from_date',
        to_date='$to_date',
        diff='$diff'
        ";

        //Execute the Query
        $res = mysqli_query($conn, $sql);
        //Check whether query executed successfully or not
    
        // header('location:'.SITEURL.'list.php');
        if($res==true)
        {
        //Query Executed and booking saved
    
        $_SESSION['booking'] = "<div class='success text-center' style='font-size: 18px'>Vehicle Booked Successfully.</div>";
        header('location:'.SITEURL.'list.php');
        
        }
        else
        {
        //Failed to save booking
        $_SESSION['booking'] = "<div class='error text-center' style='font-size: 18px'>Failed to Search Vehicles.</div>";
        header('location:'.SITEURL);
        }
        
     }
     else {
         $_SESSION['date'] = "<div class='error' style='font-size: 16px'>Select Start date +1 day after End Date</div>";
         header('location:'.SITEURL);
     
     }
        
            
}

how can i display the form details and the date difference in another page after submission

Mostafa
  • 11
  • 2
  • (Possible) side note: Do not use string interpolation or concatenation to get values into SQL queries. That's error prone and might make your program vulnerable to SQL injection attacks. Use parameterized queries. See ["How to include a PHP variable inside a MySQL statement"](https://stackoverflow.com/questions/7537377/how-to-include-a-php-variable-inside-a-mysql-statement) and ["How can I prevent SQL injection in PHP?"](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). – sticky bit Dec 26 '21 at 14:49
  • store data in session variables and use it anywhere you want on another page. $_SESSION['form_date']=$_POST; Click [here](https://stackoverflow.com/questions/676824/how-to-calculate-the-difference-between-two-dates-using-php) to see how to calculate the difference between two dates using PHP. – Developer Inside Dec 26 '21 at 15:26

0 Answers0