<----- ONLY NEED PART 3 & 4 -----> Part 1; From databases to forms: Read Databas
ID: 3820877 • Letter: #
Question
<----- ONLY NEED PART 3 & 4 ----->
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 avalue 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:
Make a link to this program from your index page.
Part 2, More databases to forms: The database weblab has a table of tools named tool_t. The table was created as follows:
Change your order form to construct the item 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 tool:
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 tool_picture or tool_descriptionattributes. Present the tool names in alphabetical order. The following is a suitable query for retrieving from the database:
This is a modification of l7p1.php, and I will test it when I test Part 1. Your program will still be named l7p1.php.
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, but see Part 4 below.
<------ This is lab excercise 6 ------>
<!DOCTYPE html>
<title>values
</title>
<meta charset="UTF-8" />
</head>
<body>
<script>
function orderFormJS()
{
var total = 0;
var tax = 0;
var hoe = document.getElementById("hoe").value;
var c_clamp = document.getElementById("c_clamp").value;
var hedge_clippers = document.getElementById("hedge_clippers").value;
var rgx=/[0-9]+/;
var valid=true;
if(hoe.length>0)
{
if(rgx.test(hoe)==false)
{
alert("Number of hoes must be a number.");
valid=false;
}
}
if(c_clamp.length>0)
{
if(rgx.test(c_clamp)==false)
{
alert("Number of clamps must be a number.");
valid=false;
}
}
if(hedge_clippers.length>0)
{
if(rgx.test(hedge_clippers)==false)
{
alert("Number of hedge clippers must be a number.");
valid=false;
}
}
if(!valid)
{
return false;
}
}
</script>
<form action="http://weblab.kennesaw.edu/formtest.php" method = "post">
<br/>
<label>Name:
<input type="text" name="Name"/>
</label>
<br>
<label>Shipping Address:
<input type="text" name="Address"/>
</label>
<br>
<label>State:
<select name="state">
<?php
$states=array('Georgia','Alabama','Florida');
foreach($states as $state)
{
echo "<option value='".$state."";
}
?>
</select>
</label>
<br>
<p>
<label> Number of hoes you would like to order? <input type="text" name="hoe" id="hoe"/>
</label>
<label> Number of c clamps you would like to order? <input type="text" name="c_clamp" id="c_clamp"/>
</label>
<label>Number of hedge clippers you would you like to order? <input type="text" name="hedge_clippers" id="hedge_clippers"/>
</label>
<br>
<br>
<label> Payment Method:
</label>
<br>
<label>Visa Card
<input type="radio" name="pay"
id="pay_visa" value="visa"
checked />
</label><br />
<label>Master Card
<input type="radio" name="pay"
id="pay_master" value="master" />
</label><br />
<label>American Express
<input type="radio" name="pay"
id="pay_american" value="american" />
</label><br />
<input type="submit" value="Submit">
</form>
</body>
</html>
Part 3; Thinking about database items: Answer the following question: The query you were given in Part 2 retrieved the tool_item_no attribute from the database. Did you do anything with it? Why, or why not? Hint: Is it remotely possible that two different tools may have the same name? Another hint: See Part 4.
Put your answer on a Web page, l7p3.html and make a link to it from your index page.
Part 4; Thinking about form data validation: Explain in no more than a paragraph each what you would have to do with your JavaScript validation to make it work with the database-driven order form. You may put your answer on the same page as Part 3. Please be sure I can tell which answer is which.
Explanation / Answer
Please find the below solutions for the above problem statement:
PART 3:
The query is as follows:
The query is not proper and it doesn't fetch any data since this query does not have a FROM clause and the fact that whenever we use the column name in the order by clause then we must have the select statement as well.
PART 04:
Have a look at the below script file which is as same as in the problem statement:
<script>
function orderFormJS()
{
var total = 0;
var tax = 0;
var hoe = document.getElementById("hoe").value;
var c_clamp = document.getElementById("c_clamp").value;
var hedge_clippers = document.getElementById("hedge_clippers").value;
var rgx=/[0-9]+/;
var valid=true;
if(hoe.length>0)
{
if(rgx.test(hoe)==false)
{
alert("Number of hoes must be a number.");
valid=false;
}
}
if(c_clamp.length>0)
{
if(rgx.test(c_clamp)==false)
{
alert("Number of clamps must be a number.");
valid=false;
}
}
if(hedge_clippers.length>0)
{
if(rgx.test(hedge_clippers)==false)
{
alert("Number of hedge clippers must be a number.");
valid=false;
}
}
if(!valid)
{
return false;
}
}
</script>
Have a look at the below html code on which the function is invoked:
<form action="http://weblab.kennesaw.edu/formtest.php" onsubmit="return orderFormJS()" method = "post">
</form>
The below is the process how is this techniques works:
01:All the variable will be initiliazed with the getElemenbyID(" ") by picking the speific html element from the html form.
02.we use the regular expressions to validate for the specific fields like number ex:
if(hoe.length>0)
{
if(rgx.test(hoe)==false)
{
alert("Number of hoes must be a number.");
valid=false;
}
}
if(c_clamp.length>0)
{
if(rgx.test(c_clamp)==false)
{
alert("Number of clamps must be a number.");
valid=false;
}
}
after validating the fields we will give alert messages so that the user will get to see on the UI as the pop up model.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.