Jump to content

Recommended Posts

:wtf:

 

the interface explains everything

 

#page1.html

<html>
  <head>



  </head>
  <body>


  <table border='0' width='50%' cellspacing='0' cellpadding='0' >
  <form name=form1 method=post  action="page2.php">

<?PHP

$postData[] = array();
$postData[0] = '9';
$postData[1] = '8';
$postData[2] = '7';
$postData[3] = '6';

?>

  
  <tr>
  <td><b>Choose your order</b></td>
  <td> </td>
  <td>
  <input type=checkbox name=scripts[] value='<?PHP $postData[0]; ?>'>pasta <br>
  <input type=checkbox name=scripts[] value='<?PHP $postData[1]; ?>'>burger <br>
  <input type=checkbox name=scripts[] value='<?PHP $postData[2]; ?>'>fries <br>
  <input type=checkbox name=scripts[] value='<?PHP $postData[3]; ?>'>chili dog <br>
  <br>
  </td>
  </tr>
  
  <tr><td align=center >
  <input type=submit value=Submit> 
  <input type=reset value=Reset></td></tr>
  
  </form> 
  </table>


  </body>
</html>

 

 

#page2.php

<?PHP


if ($_SERVER['REQUEST_METHOD'] == 'POST') {

if (isset($_POST['scripts'])) {

$cb = $_POST['scripts'];
$numRows = count($cb);

print "you have chosen the following order numbers:";
for($i=0; $i<$numRows; $i++){
print $cb[$i] . "<br>";
}


  
} 
else{
print "you have'nt checked anything!";
}




}


?>

 

What do?  :'(

Link to comment
https://forums.phpfreaks.com/topic/246833-my-order-wont-show-array-problem/
Share on other sites

im tryin to display the order no. to the other page, which is related to what the user checked.

 

it will display some numbers.

 

for example:

 

"you have chosen the following order numbers:"

"9"

"6"

 

 

this will be printed if i choose to check pasta and burger

This won't do anything without using echo. If you had looked at the html source, you'd have seen that none of the checkboxes have anything in their value= attributes.

 

<input type=checkbox name=scripts[] value='<?PHP $postData[0]; ?>'>pasta <br>

 

I was playing around, and fort this might help you, in your progress.

 

it only a rough example of making a order at a cafe.

 

can be well extended.

 

<?php session_start();

$order_id=rand(11111,5);

$_SESSION['order_id']=$order_id;

if($_POST['submit']){
    
echo "<b>MY LIITLE CAFE!</b> <br><br>";
    
$burger=$_POST['burger'];
    
  echo "Order id: ".$_SESSION['order_id']."  <br><br>";
      
      echo "Order information <br><br>";

foreach($burger as $burger){
    
    if("checked"){
       
     switch($burger){
        
        case "burger1":
        
        echo" $burger \n image 1 <br>";
        
        break;
        
        case "burger2":
        
        echo" $burger \n image 2 <br>";
        
        break;
        
        case "burger3":
        
        echo" $burger \n image 3 <br>";
        
        break;
        
        case "burger4":
        
        echo" $burger \n image 4";
        
        break;
     } 
        }
    }
    
  echo" <br><br><A HREF='javascript:history.go(-1)'>[Re order]</A>"; 
    
    exit;
}


    
echo"<p><p>";

?>


<form method="post">
<img src="" />
<input type="checkbox" name="burger[]" value="burger1" checked="checked" />
<img src=""/>
<input type="checkbox" name="burger[]" value="burger2" checked="checked"/>
<img src=""/>
<input type="checkbox" name="burger[]" value="burger3" checked="checked" />
<img src=""/>
<input type="checkbox" name="burger[]" value="burger4" checked="checked" />
<br /><br />
<input type="submit" name="submit">
</form>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.