(Solved) : Part 1 Databases Forms Read Database Access Php Copy Form Lab Exercise6 L7p1php Change Rea Q32562427 . . .
Part 1; From databases to forms: Read DatabaseAccess with PHP. Copy your form from Lab Exercise6 to l7p1.php andchange it to read the states from a database table instead ofputting them into a PHP array yourself.
The database is named weblab and the table of states is namedstate_t. The table was created as follows:
CREATE TABLE state_t (
state_abbr char(2) PRIMARY KEY,
state_name char(20),
state_zone integer);
Display the state name in the drop-down, but transmit the stateabbreviation through the form. You do this by using a valueattribute on the <option> element. The form area for Statewill look something like the following. Of course, you have tobuild this using PHP, and not just type it in.
<select name = “state”>
<option value=”AL”>Alabama</option>
<option value=”FL”>Florida</option>
<option value=”GA”>Georgia</option>
<option value=”TN”>Tennessee</option>
</select>
You will not use the state_zone attribute. In “real life” it wouldbe used for calculating shipping, maybe.
Present the state names in alphabetical order on your form. Theeasy way to do this is to have the database management system sortthem for you using an ORDER BY clause in your SQL. For those of youwho took Database long ago and far away (or not at all!), asuitable query for populating the array is this:
SELECT state_abbr, state_name from state_t ORDER BYstate_name;
From lab 6 code:
<!DOCTYPE html>
<html>
<head>
<title> My Table </title>
<script>
function validateForm() {
var a=document.getElementById(“chisels_qty”).value;
var b=document.getElementById(“hoe_qty”).value;
var c=document.getElementById(“monkey_wrench_qty”).value;
if(isNaN(a)){
alert(“Enter a numeric value for Chisels Quantity”);
return false;
}else if(isNaN(b)){
alert(“Enter a numeric value for Hoe Quantity”);
return false;
}else if(isNaN(c)){
alert(“Enter a numeric value for Monkey_wrench Quantity”);
return false;
}else{
var price= (a*4)+(b*6)+(c*8.50);
var total=price*1.07;
if (confirm(“The total cost of order is: “+total) == true)
{
return true;
}
else{ return false;
}
}
}
</script>
</head>
<body>
<h1 > My Table </h1>
<table
>
<tr>
<th>Tool Name </th>
<th>Price </th>
<th> Shipping weight </th>
</tr>
<tr>
<td> Chisels</td>
<td>$3.00 </td>
<td> 6.6 b</td>
</tr>
<tr>
<td> Hoe</td>
<td>$8.00 </td>
<td>8.8b</td>
</tr>
<tr>
<td> Monkey_wrench</td>
<td>$9.50 </td>
<td>10.2b</td>
</tr>
</table>
<br>
<br>
<form name=”myForm”action=”http://weblab.kennesaw.edu/formtest.php”
onsubmit=”return validateForm()” method=”post”>
Customer Name <input type=”text” name=”Customer name”> <br/>
Chisels Quantity <input type=”text” id=”chisels_qty”name=”Chisels unit”><br />
Hoe Quantity <input type=”text” id=”hoe_qty” name=”Hoesunit”><br />
Monkey_wrench Quantity <input type=”text” id=”monkey_wrench_qty”name=”Monkey_wrench unit”><br />
Shipping Address <input type=”text” name=”Shipping address”><br />
<tr>
<td><label for=”state”>State: </label></td>
<td><select id=”state” name=”state”>
<option>Chooose</option>
<?php
$stateslist=”Georgia,Alabama,Florida”;//store the states separatedby cama
$states= explode(‘,’,$stateslist);//spilit the states base oncama
for($i=0;$i<sizeof($states);$i++)//to loop through all theelements
{
echo ‘<option >’;
echo $states[$i];//display the states
echo ‘</option>’;
}
?>
</select>
</td>
</tr>
<tr>
<td><label for=”saw_qty”>SawQuantity</label></td>
<td><input type=”text” id=”saw_qty” ></td>
</tr>
<tr>
<td><label for=”pliers_qty”>PliersQuantity</label></td>
<td><input type=”text”id=”pliers_qty”></td>
</tr>
<tr>
<td><label for=”hedgeclippers__qty”>Hedge ClippersQuantity</label></td>
<td><input type=”text” id=”hedgeclippers__qty”></td>
</tr>
<tr>
<td>Payment Mode:<labelfor=”payment_mode_visa”></label></td>
<td><input type=”radio” name=”payment” value=”visa”checked id=”payment_mode_visa”>Visa</td>
<td><label for=”payment_mode_mastercard”></label></td>
<td><input type=”radio” name=”payment” value=”master”id=”payment_mode_mastercard”>Master Card</td>
<td><labelfor=”payment_mode_americanExpress”></label></td>
<td><input type=”radio” name=”payment”value=”american_express”id=”payment_mode_americanExpress”>AmericanExpress</td>
</tr>
<tr>
<td><br><br> <input type=”submit”value=”submit”></td>
</tr>
<input type=”submit” value=”Place order” > <inputtype=”reset” value=”Clear Form”>
</form>
</body>
</html>
Part 2, More databases to forms: The databaseweblab has a table of tools named tool_t. The table was created asfollows:
CREATE TABLE tool_t (
tool_item_no char(10) PRIMARY KEY,
tool_name char(20),
tool_price numeric(6, 2),
tool_weight numeric(4, 1),
tool_picture char(30),
tool_description varchar);
Change your order form to construct the item names, prices andweights by extracting the items from the database rather thanhard-coding them. Display every item from the database. Do notassume that there will be a given number of items.
In the database table definition above, numeric(6, 2) means theitem has a total of six digits, of which two are to the right ofthe decimal point.
Your order form should display the following items for eachtool:
Name
Price
Shipping Weight
Each idem of your form should have a box to allow the customer toenter quantity as you did in earlier assignments.
You will not need the tool_picture or tool_descriptionattributes. Present the tool names in alphabetical order. Thefollowing is a suitable query for retrieving from the database:
select tool_item_no, tool_name, tool_price,
tool_weight from tool_t
order by tool_name;
This is a modification of l7p1.php, and I will test it when I testPart 1. Your program will still be named l7p1.php.
Note: This change will “break” your JavaScript validationroutines if you still have them in your form. In real life, youwould have to fix this. However, in real life, you would havestarted with the database-driven form, so you would not have toback-track. You do not have to change your validation routines, butsee Part 4 below.
Part 3; Thinking about database items: Answerthe following question: The query you were given in Part 2retrieved the tool_item_no attribute from the database. Did you doanything with it? Why, or why not? Hint: Is it remotely possiblethat two different tools may have the same name? Another hint: SeePart 4.
Put your answer on a Web page, l7p3.html and make a link to itfrom your index page.
Part 4; Thinking about form data validation:Explain in no more than a paragraph each what you would have to dowith your JavaScript validation to make it work with thedatabase-driven order form. You may put your answer on the samepage as Part 3. Please be sure I can tell which answer iswhich.
Part 5; Reflecting on what you’ve learned: Tellat least one thing, more if possible, that you expected to get outof this course, but did not. (Please note: I’m asking for help toimprove the course. A list of things that were missing is much moreuseful to me than a statement that the course was perfect in everyway.) Put your notes on on the same page as Part 3. Please be sureI can tell which answer is which.
Expert Answer
Answer to Part 1 Databases Forms Read Database Access Php Copy Form Lab Exercise6 L7p1php Change Rea Q32562427 . . .
OR