Create a php page that will process the order using an array and display the results on another page.

your html form must look like blown:
———————————————————————————————————————————

<form action=”hardware_order.php” method=”post”>
<fieldset>
<legend>Order Form</legend>
<p><label for=”user”> Name</label> <input type=”text” name=”name” id=”user” /></p>
<p><strong>Select Some Products:</strong> <br>
<select name=”products[]” multiple>
<option value=”Sonic Screwdriver”>Sonic Screwdriver</option>
<option value=”Hammer”>Hammer</option>
<option value=”Drill”>Drill</option>
<option value=”Spanner”>Spanner</option>
</select>
<p><input type=”submit” name=”submit” value=”send”></p>
</fieldset>
</form>

————————————————————————————————————————
there are two ways can proceed this: one is :
————————————————————————————————————————-
<?php
$name =trim($_POST[‘name’]);
if(empty($_POST[‘products’])||empty($name))
{
echo “nothing has been selected”;
}
else
{
echo “Thanks “.$name.” your select products is “;

foreach($_POST[‘products’] as $o)
{
echo $o.”<br/>”;
}
}
?>
————————————————————————————————————————–
another ways is teacher’s answers:
———————————————————————————————————————————<?php
$name =trim($_POST[‘name’]);
if (!empty($name))
{     echo “<p>Welcome <b>$name</b>!</p>”;
}
else
{
echo “<p>Enter a name</p>”;
}

if(!empty($_POST[‘products’]))
{
echo “<ul>”;
echo “<p>Your product choices are:<br/>”;
foreach ($_POST[‘products’] as $value)
{
echo “<li>$value</li>”;
}
echo “</ul>”;
}
else
{
echo “<p> Nothing selected</p>”;
}
?>

 

Advertisements

2 thoughts on “Create a php page that will process the order using an array and display the results on another page.”

  1. I blog often annd I genuinely thank you foor youur information. The article hhas rerally peaked my interest.
    I’m going to bookmartk your site annd kerep checking
    ffor new information about oncce a week. I
    olted iin for your RSS feded aas well.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s