More databases to forms PHP and SQL Use Lab Exercise 6 below

More databases to forms (PHP and SQL): Use Lab Exercise 6 (below). The database weblab has a table of fruit named fruit_t. The table was created as follows:

Change your fruit order form to construct the table of names, prices and weights by extracting the items from the database rather than hard-coding them. Display every item from the database. Do not assume that there will be a given number of items.

In the database table definition above, numeric(6, 2) means the item has a total of six digits, of which two are to the right of the decimal point.

Your order form should display the following items for each fruit:

-Name

-Price

-Shipping Weight

Each idem of your form should have a box to allow the customer to enter quantity as you did in earlier assignments.

You will not need the fruit_picture or fruit_description attributes. Present the fruit names in alphabetical order. The following is a suitable query for retrieving from the database:

Note: This change will \"break\" your JavaScript validation routines if you still have them in your form. In real life, you would have to fix this. However, in real life, you would have started with the database-driven form, so you would not have to back-track. You do not have to change your validation routines

Lab Exercise 6:

<!DOCTYPE html>
<html lang = \"en\">
<head>
<title>l6p2</title>
<meta charset = \"UTF-8\"/>

<script type = \"text/javascript\">

function quantity(){
var apples = parseInt(document.getElementById

(\"apple\").value);
var pumpkins = parseInt(document.getElementById
(\"pumpkin\").value);
var bananas = parseInt(document.getElementById
(\"banana\").value);

if(isNaN(apples))
alert(\"Enter a number (Apple)\");
else
if(isNaN(pumpkins))
alert(\"Enter a number (Pumpkin)\");
else
if(isNaN(bananas))
alert(\"Enter a number (Banana)\");
else
{
document.forms[\'orderform\'].submit();
}
}

</script>

</head>
<body>
<h1 style = \"text-align:center\">Lab 4, Part 3</h1>
<h2 style = \"text-align:center\">IT 3203</h2>

<h4>Customer Order Form</h4>

<form name = newCalculation
action = \"http://weblab.kennesaw.edu/formtest.php\" id = \"orderform\">
<p>
<!--Name and address boxes-->
<label> Name:
<input type = \"text\" name = \"name\"
size = \"35\"/>
</label><br/>

<label> Address:
<input type = \"text\" name = \"street\"
size = \"35\"/>
</label><br/>

<label> City, ZIP:
<input type = \"text\" name = \"city\"
size = \"35\"/>
</label><br/>

Select State:

<?php
$states = array(\"Al\", \"Ga\", \"Fl\");
echo \"<select name=state>\";
for($i = 0; $i < count($states); $i++)
echo \"<option value = \".$states[$i].\">\".$states[$i].\"</option>\";
echo \"</select>\";
?>
<br/>

<!--item table-->
<table>
<tr>
<th>Fruit</th>
<th>Price per Weight</th>
<th>Quantity</th>
</tr>

<tr>
<td>Apples (3 lbs.)</td>
<td>$5.97</td>

<td> <input type = \"text\" id = \"apple\"
size = \"7\"/>
</td>
</tr>

<tr>
<td>Pumpkins (15 lbs.)</td>
<td>$8.49</td>
<td> <input type = \"text\" id = \"pumpkin\"
size = \"7\"/>
</td>
</tr>

<tr>
<td>Bananas (2 lbs)</td>
<td>$1.80</td>
<td><input type = \"text\" id = \"banana\"
size = \"7\"/>
</td>
</tr>

</table>


<!--Payment method, radio button-->
<h4> Payment Method</h4>
<p>
<label> <input type = \"radio\" name = \"payment\"
value = \"visa\"/> Visa
</label>

<label> <input type = \"radio\" name = \"payment\"
value = \"mc\"/> MasterCard
</label>

<label> <input type = \"radio\" name = \"payment\"
value = \"ae\"/> American Express
</label><br/>
</p>

<!--submit and clear-->

<p>
Confirm Order:<br/>
<input type = \"button\" value = \"Submit\" onclick = \"return quantity();\"/>
<input type = \"reset\" value = \"Clear\"/>
</p>
</form>
</body>
</html>

Solution

<!DOCTYPE html>
<html lang = \"en\">
<head>
<title>l6p2</title>
<meta charset = \"UTF-8\"/>

<script type = \"text/javascript\">

function quantity(){
var apples = parseInt(document.getElementById

(\"apple\").value);
var pumpkins = parseInt(document.getElementById
(\"pumpkin\").value);
var bananas = parseInt(document.getElementById
(\"banana\").value);

if(isNaN(apples))
alert(\"Enter a number (Apple)\");
else
if(isNaN(pumpkins))
alert(\"Enter a number (Pumpkin)\");
else
if(isNaN(bananas))
alert(\"Enter a number (Banana)\");
else
{
document.forms[\'orderform\'].submit();
}
}

</script>

</head>
<body>
<h1 style = \"text-align:center\">Lab 4, Part 3</h1>
<h2 style = \"text-align:center\">IT 3203</h2>

<h4>Customer Order Form</h4>

<form name = newCalculation
action = \"http://weblab.kennesaw.edu/formtest.php\" id = \"orderform\">
<p>
<!--Name and address boxes-->
<label> Name:
<input type = \"text\" name = \"name\"
size = \"35\"/>
</label><br/>

<label> Address:
<input type = \"text\" name = \"street\"
size = \"35\"/>
</label><br/>

<label> City, ZIP:
<input type = \"text\" name = \"city\"
size = \"35\"/>
</label><br/>

Select State:

<?php
$states = array(\"Al\", \"Ga\", \"Fl\");
echo \"<select name=state>\";
for($i = 0; $i < count($states); $i++)
echo \"<option value = \".$states[$i].\">\".$states[$i].\"</option>\";
echo \"</select>\";
?>
<br/>

<!--item table-->
<table>
<tr>
<th>Fruit</th>
<th>Price per Weight</th>
<th>Quantity</th>
</tr>

<tr>
<td>Apples (3 lbs.)</td>
<td>$5.97</td>

<td> <input type = \"text\" id = \"apple\"
size = \"7\"/>
</td>
</tr>

<tr>
<td>Pumpkins (15 lbs.)</td>
<td>$8.49</td>
<td> <input type = \"text\" id = \"pumpkin\"
size = \"7\"/>
</td>
</tr>

<tr>
<td>Bananas (2 lbs)</td>
<td>$1.80</td>
<td><input type = \"text\" id = \"banana\"
size = \"7\"/>
</td>
</tr>

</table>


<!--Payment method, radio button-->
<h4> Payment Method</h4>
<p>
<label> <input type = \"radio\" name = \"payment\"
value = \"visa\"/> Visa
</label>

<label> <input type = \"radio\" name = \"payment\"
value = \"mc\"/> MasterCard
</label>

<label> <input type = \"radio\" name = \"payment\"
value = \"ae\"/> American Express
</label><br/>
</p>

<!--submit and clear-->

<p>
Confirm Order:<br/>
<input type = \"button\" value = \"Submit\" onclick = \"return quantity();\"/>
<input type = \"reset\" value = \"Clear\"/>
</p>
</form>
</body>
</html>

More databases to forms (PHP and SQL): Use Lab Exercise 6 (below). The database weblab has a table of fruit named fruit_t. The table was created as follows: Cha
More databases to forms (PHP and SQL): Use Lab Exercise 6 (below). The database weblab has a table of fruit named fruit_t. The table was created as follows: Cha
More databases to forms (PHP and SQL): Use Lab Exercise 6 (below). The database weblab has a table of fruit named fruit_t. The table was created as follows: Cha
More databases to forms (PHP and SQL): Use Lab Exercise 6 (below). The database weblab has a table of fruit named fruit_t. The table was created as follows: Cha
More databases to forms (PHP and SQL): Use Lab Exercise 6 (below). The database weblab has a table of fruit named fruit_t. The table was created as follows: Cha

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site