From databases to forms: Read Database Access with PHP. Copy your form from Lab
ID: 3819758 • Letter: F
Question
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:
Make a link to this program from your index page.
The program for form is-
!DOCTYPE html>
<html>
<head>
<title> praneet.16p3.php </title>
<meta http-equiv="application" content="application/xhtml+xml;charset=UTF-8">
<script>
function allnumeric(inputtxt)
{
var numbers = /^[0-9]+$/;
// For count_network
if(inputtxt.count_network.value.match(numbers) inputtxt.count_memory.value.match(numbers) inputtxt.count_hdd.value.match(numbers))
{
alert('Your Registration number has accepted....');
inputtxt.count_network.focus();
return true;
}
else
{
alert('Please input numeric characters only');
inputtxt.count_memory.focus();
return false;
}
}
</script>
</head>
<body>
<form name = "myform" action="/formtest.php">
Customer name:
<input type="text" name="Customer">
<br><br>Address:
<input type="text" name="address">
<br><br>
State:
<select name="state">
<?php
$arr=array(" Georgia", "Alabama"," Florida");
for($i=0;$i<count($arr);$i++)
{
echo "<option value='" . $arr[$i] ."'>" . $arr[$i] ."</option>";
}
?>
</select>
<br><br>
<p>Payment Choices</p>
<input type="radio" name="payment" value="Visa" id="VisaPayment" = checked
<label for="VisaPayment"> Visa</label><br>
<input type="radio" name="payment" value="MasterCard" id="MasterCardPayment" >
<label for="MasterCardPayment"> MasterCard</label><br>
<input type="radio" name="payment" value="AmericanExpress" id="AmericanExpressPayment" >
<label for="AmericanExpressPayment"> AmericanExpress</label>
<br><br>
<b> Enter quantity :-</b>
<br><br>
List-Memory Upgrade :- <input type="text" name="count_memory" id = "count_memory">
<br><br>
List-HDD Upgrade :- <input type="text" name="count_hdd" id = "count_hdd">
<br><br>
List- Network Upgrade :- <input type="text" name="count_network" id = "count_network">
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
Explanation / Answer
!DOCTYPE html>
<html>
<head>
<title> praneet.16p3.php </title>
<meta http-equiv="application" content="application/xhtml+xml;charset=UTF-8">
<script>
function allnumeric(inputtxt)
{
var numbers = /^[0-9]+$/;
// For count_network
if(inputtxt.count_network.value.match(numbers) inputtxt.count_memory.value.match(numbers) inputtxt.count_hdd.value.match(numbers))
{
alert('Your Registration number has accepted....');
inputtxt.count_network.focus();
return true;
}
else
{
alert('Please input numeric characters only');
inputtxt.count_memory.focus();
return false;
}
}
</script>
</head>
<body>
<form name = "myform" action="/formtest.php">
Customer name:
<input type="text" name="Customer">
<br><br>Address:
<input type="text" name="address">
<br><br>
State:
<select name="state">
<?php
$arr=array(" Georgia", "Alabama"," Florida");
for($i=0;$i<count($arr);$i++)
{
echo "<option value='" . $arr[$i] ."'>" . $arr[$i] ."</option>";
}
?>
</select>
<br><br>
<p>Payment Choices</p>
<input type="radio" name="payment" value="Visa" id="VisaPayment" = checked
<label for="VisaPayment"> Visa</label><br>
<input type="radio" name="payment" value="MasterCard" id="MasterCardPayment" >
<label for="MasterCardPayment"> MasterCard</label><br>
<input type="radio" name="payment" value="AmericanExpress" id="AmericanExpressPayment" >
<label for="AmericanExpressPayment"> AmericanExpress</label>
<br><br>
<b> Enter quantity :-</b>
<br><br>
List-Memory Upgrade :- <input type="text" name="count_memory" id = "count_memory">
<br><br>
List-HDD Upgrade :- <input type="text" name="count_hdd" id = "count_hdd">
<br><br>
List- Network Upgrade :- <input type="text" name="count_network" id = "count_network">
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.