Click here to Skip to main content
15,867,877 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Everyone, I am trying to create a food order site.

After user click on buy Button under the food, i want to redirect user to final_order page with the Food selected by user.

see my codes below.

What I have tried:

while($row=mysqli_fetch_assoc($query)){
            
            
            echo "<div class='col-5'>";
            
            
           echo "<br>". $food_name= $row['food_name'];
           echo "<br>". $food_info = $row['food_info'];
           echo "<br>". $food_price = $row['food_price'];
           echo "<br>". $vendor_id = $row['vendor_id'];
           echo "<br>". $default_miles = $row['default_miles'];
           echo "<br>". $food_date= $row['date'];

           $foods= array($food_name, $food_info, $food_price, $vendor_id, $default_miles);

           echo "echo <form action='cart.php' method='POST'>;
            
           

            
                <input type='hidden' name='food_name' value='<?php $food_name; ?>'>
                <input type='hidden' name='food_info' value='<?php $food_info; ?>'> 
                <input type='hidden' name='food_price' value='<?php $food_price; ?>'> 
                <input type='hidden' name='vendor_id' value='<?php $vendor_id; ?>'> 
                <input type='hidden' name='default_miles' value='<?php $default_miles; ?>'>        
               <input class='btn btn-warning' type='submit' name='submit' value='Buy Food'/>
           </form><br>     
       
       ";
       echo "</div>";
       
    // REQUESTING FROM HTML FORM

    
    $submit= $_POST['submit'];

    // I TRIED SET SESSION HERE FOR SUBMIT BUTTON
    $_SESSION['submit_b']= array ($submit=>"$food_name" );

    // I TRIED RETRIEVE BACK SESSION HERE FOR SUBMIT BUTTON
    $for_foods= $_SESSION['submit'];


    // MY CODES
    if(isset($_POST['submit'])){

        $sql= "INSERT INTO "
        echo "Food Successfully<br>";
        echo $food_name;
       // header('location: final_order.php');

        }}}
?>
Posted
Comments
OriginalGriff 4-Dec-22 11:07am    
And?
What have you tried?
Where are you stuck?
What help do you need?

Use the "Improve question" widget to edit your question and provide better information.
Member 15627495 5-Dec-22 8:38am    
as a reminder , '$_SESSION' and '$_POST', '$_GET' and '$row' are 'var arrays'.
you can use them as they are ( container for var values ).

when you write :
$one_var = $_GET['var_one']; , you are increasing 'memory amount' for the script execution, if you don't apply a function on $_GET[....] , you're creating a new var '$one_var' for nothing.
Member 15627495 5-Dec-22 8:46am    
'echo' instruction in php, is not only a display function. it stamps in the /output buffer/ the datas for later, before being sent to the client as web page base and content.

echo "<div class='col-5'>";
            
            
           echo "<br>". $food_name= $row['food_name'];
           echo "<br>". $food_info = $row['food_info'];
           echo "<br>". $food_price = $row['food_price'];
           echo "<br>". $vendor_id = $row['vendor_id'];
           echo "<br>". $default_miles = $row['default_miles'];
           echo "<br>". $food_date= $row['date'];

could be :
$display_output = "<div class='col-5'>";
           $display_output .= "<br>". $row['food_name'];
           $display_output .= "<br>". $row['food_info'];
           $display_output .=  $row['food_price'];
           $display_output .= "<br>". $row['vendor_id'];
           $display_output .= "<br>". $row['default_miles'];
           $display_output .= "<br>". $row['date'];
           
           echo $display_output; // with '.=' for concatening Strings. same display, same vars contents.
Member 15627495 5-Dec-22 9:16am    
this way, you can have only 'ONE' echo() function line in your php script.
Jeffersonballer 5-Dec-22 10:02am    
Thanks... But If user click on any button how do i get the data on next page... As final Order for what user click

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900