How to use a PHP function to covert this program?

Discussion in 'PHP' started by sunnyboy1984, Mar 5, 2007.

  1. #1
    Can anyone offer some advice about how to convert the following receipt code by using a function called
    select_beverage($dinner)

    The entree chosen through the HTML form should be passed into the $dinner parameter, and the result should be returned to the program to be processed with the rest of the receipt.


    <ol style="font-size:16px;">
    
    <li><h3>This is your receipt</h3>
    
    <?
    $my_Steak = "Steak";
    $my_Salmon = "Salmon";
    $my_BarbecuePork = "BarbecuePork";
    $my_Chicken = "Chicken";
    
    echo "<BR>Our meal includes ".$my_Steak.", 
        ".$my_Salmon.", ".$my_BarbecuePork.", and ".$my_Chicken."!<br>";
    
    ?>
    
    <?
    $my_dinner = $_GET ["my_dinner"];
    
    
       if ($my_dinner == "Steak")
    {
       echo "<i>Your chosen meal is steak.Your recommended drink is red wine</i>";
    
    }
     else if 
        ($my_dinner == "Salmon")
    {
           echo "<i>Your chosen meal is salmon. Your recommended drink is white wine</i>";
    }
    
    else if 
       ($my_dinner == "BarbecuePork")
    {
       echo "<i>Your chosen meal is barbecuepork. Your recommended drink is coke</i>";
    
    
    }
    
    
    else
    
       
    {
      echo "<i>Your chosen meal must be chicken.Your recommended drink is apple juice";
    
    }
    ?>
    
    <h3>Looking forward to your next visit :) </h3>
    
    
    
    </ol>
    PHP:
    This is the HTML code:


    <body>
    <h3>Please choose a entre for your dinner </h3>

    <form method="GET" action="Lesson.php">
    Your dinner:

    <select name="my_dinner">
    <option value="">Please choose...
    <option value="Steak">Steak
    <option value="Salmon">Salmon
    <option value="BarbecuePork">BarbecuePork
    <option value="Chicken">Chicken
    </select>


    <input type=submit value="SUBMIT">

    </form>
    </body>
     
    sunnyboy1984, Mar 5, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Like this?

    
    function select_beverage($dinner)
    {
    	switch ($dinner)
    	{
    		case 'Steak':
    			echo "<i>Your chosen meal is steak.Your recommended drink is red wine</i>";
    			break;
    		
    		case 'Salmon':
    			echo "<i>Your chosen meal is salmon. Your recommended drink is white wine</i>";
    			break;
    		
    		case 'BarbecuePork':
    			echo "<i>Your chosen meal is barbecuepork. Your recommended drink is coke</i>";
    			break;
    		
    		default:
    			echo "<i>Your chosen meal must be chicken.Your recommended drink is apple juice";
    	}
    }
    
    PHP:
     
    nico_swd, Mar 5, 2007 IP
  3. sunnyboy1984

    sunnyboy1984 Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    But how to change the HTML? The value needs to be processed by the HTML form. use <select_name = "dinner">??
     
    sunnyboy1984, Mar 5, 2007 IP
  4. cowguru2000

    cowguru2000 Member

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #4
    Make the form method POST and instead of $_GET[''], use $_POST['mydinner'].
     
    cowguru2000, Mar 5, 2007 IP