Tag Archives: MySQL

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