Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The database management system installed on the weblab server is MariaDB, which

ID: 653224 • Letter: T

Question

The database management system installed on the weblab server is MariaDB, which uses the MySQL calls; you will need to use mysql_ API functions for this assignment. Just follow the examples in the link that's in Part 1 and you'll be OK.

Part 1; From databases to forms: Read Database Access with PHP. Copy your form from Lab Exercise6 to l7p1.php and change it to read the states from a database table instead of putting them into a PHP array yourself.

The database is named weblab and the table of states is named state_t. The table was created as follows:

Display the state name in the drop-down, but transmit the state abbreviation through the form. You do this by using a value attribute on the <option> element. The form area for State will look something like the following. Of course, you have to build this using PHP, and not just type it in.

You will not use the state_zone attribute. In "real life" it would be used for calculating shipping, maybe.

Present the state names in alphabetical order on your form. The easy way to do this is to have the database management system sort them for you using an ORDER BY clause in your SQL. For those of you who took Database long ago and far away (or not at all!), a suitable query for populating the array is this:

<!DOCTYPE html>
<head>
<meta charset="UTF-8" >

<title> Tool Order Form </title>

<script type = "text/javascript">

function validateForm(){
var x=document.forms["Order Form"]["Price"].value;
if (isNaN(x)) {
alert("Price must be a number");
return false;
}
}
</script>

</head>

<body>

<h3> Tool Order Form </h3>

<table>

<tr>

<th> Product Name </th>

<th> Price </th>

<th> Quantity </th>

</tr>


<tr>

<th> Tree Trimmer </th>

<td> $45.00 </td>

<td> <input type = "text" id = "trimmer" size ="5"> </td>

</tr>

<tr>

<th> plyers </th>

<td> $3.99 </td>

<td> <input type = "text" id = "plyers" size = "5"> </td>

</tr>

<tr>

<th> hammer</th>

<td> $15.99 </td>

<td> <input type = "text" id = "hammer" size = "5"></td>

</tr>

</table>

<br>
<br>

<h3>Billing Information</h3>

<p><label><input type="radio" name="payment" value="visa" checked="checked">Visa</label>
<br>
<label><input type="radio" name="payment" value="master card" checked="checked">Master Card</label>
<br>
<label><input type="radio" name="payment" value="american express" checked="checked">American Express</label>
<br>
<label><input type="radio" name="payment" value="discover" checked="checked">Discover</label>
<br>

<label>Credit card number: <input type="text" name="Credit card number" size="25"></label>
<br>
<br>
<label>Expiration date month/year (xx/xxxx): <input type="text" name="expiration date month/year" size="7"></label>
<br>
<br>
<label>CID: <input type="text" name="CID" size="3"></label>

<br>
<br>
<h3>Shipping Information</h3>

Customer Name: <input type="text" name="customername">
<br>
<br>
Address: <input type="text" name="address">
<br>
<br>
    <?php
    $states =array("select state","Georgia", "Alabama", "Florida");

    echo "<select name=state>";
    for($i=0; $i < count($states); $i++)
    echo "<option value=". $states[$i] .">" . $states[$i] . "</option>";

    echo "</select>";
    ?>

<br>
<br>

<input type = "submit" value = "Submit Order" />

<input type = "reset" value = "Clear Order Form" />
<br>
<br>
<br>

</form>

</body>

</html>

Explanation / Answer

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Price Form</title>
</head>
  <body>
<form action="a12p4.php"
  method = "post">
<h3> Price Form</h3>
<p>Last Name <input type="text" name="lastname" size="25" /></p>
<p>First Name <input type="text" name="firstname" size="25" /></p>
<p>Address<input type="text" name="address" size="35" /></p>
<p>City<input type="text" name="city" size="25" /></p>
<p>State<select name = "state">
<?php
$state = array( 'AL' => 'Alabama',
           'FL' => 'Florida',
           'GA' => 'Georgia');

foreach ($state as $x => $name) {
echo "<option value="$x">$name</option> ";


}
?>
</p>
</select>
<p>Zip<input type="text" name="zip" size="25" /></p>
<br></br>
<h3> Products for Sale</h3>
<p>
<input type ="text" name= "saw" size = "5"/> Saw @ $10.00</p>

<p>
<input type ="text" name= "hoe" size = "5" /> Hoe @ $18.00</p>
<p>
<input type ="text" name= "tree_trimmer" size = "5" /> Tree-Trimmer @ $ 35.00</p>
<br></br>

<h3> Method of Payment</h3>
<p>
<input type ="radio" name= "Payment" value= "Visa" /> Visa
<input type ="radio" name= "Payment" value= "Mastercard" /> Mastercard
<input type ="radio" name= "Payment" value= "Discover" /> Discover
</p>

<p><input type = "submit" value = "Submit Form"/></p>

</form>
  </body>

</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote