In this assignment, you will use PHP to build an application that allows a user to insert new records into a relational database. (ALL PARTS OF TABLES (file) ARE HERE)
1. HTML Static Content – Web Form
• On the landing page, create web forms that collect information from the user.
– The first web form should collect the information required to insert a new Part into the PARTS table. After the data has been successfully validated, submit it to parts.php. (3 marks)
– The second web form should collect the information required to insert a new Vendor into the VENDORS table. After the data has been successfully validated, submit it to vendors.php. (3 marks)
– The final web form will be used to construct a parameter query. After the data has been successfully validated, submit it to parameter.php. (1 mark)
• Refer to “assignment5.mdb” for more details about the table schemas.
2. HTML Static Content – Instructions (1 mark)
Be sure to explain to the user what your web application is supposed to do. Include details on how to use the application. Explicitly describe the construction of the parameter query.
3. JavaScript – Form Validation
• All user inputs must be validated so that they match the data types of the corresponding field from the database. Do not allow null fields if the data is required. (4 marks)
• If any errors exist, display a compound message that includes all of the error messages. Do not use a JavaScript popup box for this purpose. (2 marks)
4. PHP – Form Validation
• All user inputs must be validated so that they match the data types of the corresponding field from the database. Do not allow null fields if the data is required. (4 marks)
• If any errors exist, display a compound message that includes all of the error messages. (2 marks)
5. PHP – Data Persistence From parts.php and vendors.php:
• After the data has been successfully validated, display a message that summarizes the data that the user provided. (2 marks)
• Insert the data into the corresponding table. (2 marks)
6. PHP – Parameter Query (2 marks) From parameter.php:
• Create a parameter query incorporating the information that the user submitted. You are completely free to make the query as complicated as you like. Execute the query and display the results.
7. Programming Style and Standards (2 marks) It is a good idea to practice conforming to a set of programming standards. Refer to the posted summary of the Programming Standards used by the CP/CPA programs.
——————————————————————————————————————————————————————————————————————————————–
——————————————————————————————————————————————————————————————————————————————–
ASSIGNMENT5.MDB file (SCREENSHORTS OF PARTS AND VENDORS)
PARTS
PartID, VendorNo, Description, OnHand, OnOrder, Cost, ListPrice
——————————————————————————————————————————————————————————————————————————————–
VENDORS
THE TEACHER ONLY PROVIDED US PARTS & VENDOR TABLE
Parti. Vendor-▼ Description 3820 Dive kayak 3820 Underwater Diver Vehicle 3511 Regulator System 5641 Second Stage Regulator 3511 Regulator System 3511 Second Stage Regulator 3511 Regulator System 3511 Alternate Inflation Regulator 3511 Second Stage Regulator 3511 First Stage Regulator 6588 Second Stage Regulator 6588 Depth/Pressure Gauge Console 3511 Electronic Console 3511 Depth/Pressure Gauge 3511 Personal Dive Sonar 3511 Compass Console Mount 3511 Compass (meter only) 3511 Depth/Pressure Gauge 3511 Electronic Console w/ options 2014 Direct Sighting Compass 2014 Dive Computer 2014 Navigation Compass 2014 Wrist Band Thermometer (F 2014 Depth/Pressure Gauge (Digital) 2014 Depth/Pressure Gauge (Analog) 2014 Wrist Band Thermometer (C) 6588 Dive Computer 3511 Stabilizing Vest 3511 Front Clip Stabilizing Vest 16 1356.75 3999.95 2 1680 165 216 117.5 88 124.1 70 119.35 35 73.53 154.8 85.8 99.9 64.6 95.79 24 73.32 12 120.9 48.3 72.85 10.15 24.96 120 76.22 189 4 365 75 341 166 100 43 135 140 10 430 260 270 170 10 146 12 390 105 235 29 52 226 211 168 183 420 12 12.582 34.95 179 20 9.17719.95 18 149 119 19 15 2 76.97 7.92 53.64 39.27 6.48 253.5 146.2 128.8 10 12 16 12 26 10 67 430
Expert Answer
#)part.html
<!DOCTYPE html>
<html>
<head>
<title>PART</title>
<script type=”text/javascript”>
function valid()
{
var b=window.document.part.pid.value;
var name=new RegExp(“^[a-zA-Z.@]+$”);
var d=window.document.part.vno.value;
var no=new RegExp(“^[0-9]+$”);
var f=window.document.part.desc.value;
var h=window.document.part.oh.value;
var i=window.document.part.oo.value;
var j=window.document.part.cost.value;
var k=window.document.part.lp.value;
if(!(b.match(no))
{
alert(“Enter number only.”);
window.document.part.cname.value=””;
window.document.part.cname.focus();
return false;
}
else if(!(d.match(no))
{
alert(“Enter number only.”);
window.document.part.cname.value=””;
window.document.part.cname.focus();
return false;
}
else if(!(f.match(name))
{
alert(“Enter name only.”);
window.document.part.cname.value=””;
window.document.part.cname.focus();
return false;
}
else if(!(h.match(no))
{
alert(“Enter number only.”);
window.document.part.cname.value=””;
window.document.part.cname.focus();
return false;
}
else if(!(i.match(no))
{
alert(“Enter number only.”);
window.document.part.cname.value=””;
window.document.part.cname.focus();
return false;
}
else if(!(j.match(no))
{
alert(“Enter number only.”);
window.document.part.cname.value=””;
window.document.part.cname.focus();
return false;
}
if(!(k.match(no))
{
alert(“Enter number only.”);
window.document.part.cname.value=””;
window.document.part.cname.focus();
return false;
}
else{
return true;
}
}
</script>
</head>
<body>
<h3 align=”center”>PARTS</h3>
<form style=”color: blue” name=”part” method=”post” action=”part.php”><br>
<table align=”center” ><tr> <td><label>PART ID:</label></td> <td> <input type=”text” name=”pid”><br></td></tr>
<tr><td><label>VENDOR NO:</label></td> <td><input type=”text” name=”vno”><br></td></tr>
<tr><td><label>Description:</label></td> <td><input type=”text” name=”desc”><br></td></tr>
<tr><td><label>OnHand:</label></td> <td><input type=”text” name=”oh”><br></td></tr>
<tr><td><label>On Order:</label></td> <td><input type=”text” name=”oo”><br></td></tr>
<tr><td><label>Cost:</label></td> <td><input type=”text” name=”cost”><br></td></tr>
<tr><td><label>Last Price:</label></td> <td><input type=”text” name=”lp”><br></td></tr>
<td></td><td><input type=”submit” value=”submit” onClick=”return valid()”><input type=”reset” name=”reset”></td></tr>
</table>
</form>
</body>
</html>
#)vendor.php
<!DOCTYPE html>
<html>
<head>
<title>vendor</title>
<script type=”text/javascript”>
function valid()
{
var b=window.document.part.pid.value;
var name=new RegExp(“^[a-zA-Z.@]+$”);
var d=window.document.part.vno.value;
var no=new RegExp(“^[0-9]+$”);
var f=window.document.part.vname.value;
var h=window.document.part.add.value;
var i=window.document.part.add1.value;
var j=window.document.part.city.value;
var k=window.document.part.pro.value;
var l=window.document.part.postcode.value;
var m=window.document.part.Country.value;
var n=window.document.part.ph.value;
var o=window.document.part.fax.value;
if(!(b.match(no))
{
alert(“Enter number only.”);
window.document.part.cname.value=””;
window.document.part.cname.focus();
return false;
}
else if(!(d.match(no))
{
alert(“Enter number only.”);
window.document.part.cname.value=””;
window.document.part.cname.focus();
return false;
}
else if(!(f.match(name))
{
alert(“Enter name only.”);
window.document.part.cname.value=””;
window.document.part.cname.focus();
return false;
}
else if(!(h.match(name))
{
alert(“Enter name only.”);
window.document.part.cname.value=””;
window.document.part.cname.focus();
return false;
}
else if(!(j.match(name))
{
alert(“Enter name only.”);
window.document.part.cname.value=””;
window.document.part.cname.focus();
return false;
}
else if(!(k.match(no))
{
alert(“Enter number only.”);
window.document.part.cname.value=””;
window.document.part.cname.focus();
return false;
}
else if(!(l.match(no))
{
alert(“Enter number only.”);
window.document.part.cname.value=””;
window.document.part.cname.focus();
return false;
}
else if(!(m.match(name))
{
alert(“Enter name only.”);
window.document.part.cname.value=””;
window.document.part.cname.focus();
return false;
}
else if(!(m.match(no))
{
alert(“Enter number only.”);
window.document.part.cname.value=””;
window.document.part.cname.focus();
return false;
}
else if(!(n.match(no))
{
alert(“Enter number only.”);
window.document.part.cname.value=””;
window.document.part.cname.focus();
return false;
}
else if(!(o.match(no))
{
alert(“Enter number only.”);
window.document.part.cname.value=””;
window.document.part.cname.focus();
return false;
}
else{
return true;
}
}
</script>
</head>
<body>
<h3 align=”center”>VENDOR</h3>
<form style=”color: blue” name=”part” method=”post” action=”part.php”><br>
<table align=”center” ><tr> <td><label>PART ID:</label></td> <td> <input type=”text” name=”pid”><br></td></tr>
<tr><td><label>VENDOR NO:</label></td> <td><input type=”text” name=”vno”><br></td></tr>
<tr><td><label>VendorName</label></td> <td><input type=”text” name=”vname”><br></td></tr>
<tr><td><label>Address1 :</label></td> <td><input type=”text” name=”add1″><br></td></tr>
<tr><td><label>Address:</label></td> <td><input type=”text” name=”add”><br></td></tr>
<tr><td><label>City:</label></td> <td><input type=”text” name=”city”><br></td></tr>
<tr><td><label>pro:</label></td> <td><input type=”text” name=”pro”><br></td></tr>
<tr><td><label>Post code:</label></td> <td><input type=”text” name=”postcode”><br></td></tr>
<tr><td><label>Country:</label></td> <td><input type=”text” name=”country”><br></td></tr>
<tr><td><label>Phone:</label></td> <td><input type=”text” name=”ph”><br></td></tr>
<tr><td><label>Fax:</label></td> <td><input type=”text” name=”fax”><br></td></tr>
<td></td><td><input type=”submit” value=”submit” onClick=”return valid()”><input type=”reset” name=”reset”></td></tr>
</table>
</form>
</body>
</html>
#)part.php
<html>
<?php
//collect the details with the same variable name
$pid=$_POST[‘pid’];
$vno=$_POST[‘vno’];
$desc=$_POST[‘desc’];
$oh=$_POST[‘oh’];
$oo=$_POST[‘oo’];
$cost=$_POST[‘cost’];
$lp=$_POST[‘lp’];
if(($pid==””) &&($vno==””)) //i check the first two fields in php
{
echo “<br/><br/><font color=’blue’><h3>You Should Enter all the Details.</h3></font>”;
}
else{
//2.Connect to Mysql database from–>open connecton
$con=mysql_connect(“localhost”,”root”,””) or die(“cannot connect to MYSQL Server”);
#echo “MYSQL connection successfull”
//3.select the database(not the table)
$db=mysql_select_db(“part”) or die(“cannot use the database part”);
#echo “database part being used”;
//4.prepare an SQL querry to do insert
$query=”INSERT INTO part VALUES(‘$pid’,’$vno’,’$desc’,$oo,’$cost’,’$lp’)”;
#echo “the querry prepared is:$query”;
//5.perform the SELECT operation(excute qurry)
mysql_query($query) or die(“<br/><br/><br/>insertion not possible:”); //user define error
}
//6.close the db connection
mysql_close($con);
?>
</html>
#)vendor.php
<html>
<?php
//collect the details with the same variable name
$pid=$_POST[‘pid’];
$vno=$_POST[‘vno’];
$vname=$_POST[‘vname’];
$add1=$_POST[‘add1’];
$add=$_POST[‘add’];
$city=$_POST[‘city’]; /// collect the details
$pro=$_POST[‘pro’];
$postcode=$_POST[‘postcode’];
$country=$_POST[‘country’];
$ph=$_POST[‘ph’];
$fax=$_POST[‘fax’];
if(($pid==””) &&($vno==””)) //i check the first two fields in php
{
echo “<br/><br/><font color=’blue’><h3>You Should Enter all the Details.</h3></font>”;
}
else{
//2.Connect to Mysql database from–>open connecton
$con=mysql_connect(“localhost”,”root”,””) or die(“cannot connect to MYSQL Server”);
#echo “MYSQL connection successfull”
//3.select the database(not the table)
$db=mysql_select_db(“vendor”) or die(“cannot use the database vendor”);
#echo “database part being used”;
//4.prepare an SQL querry to do insert
$query=”INSERT INTO part VALUES(‘$pid’,’$vno’,’$vname’,’$add1′,’$add’,’$city’,’$pro’,’$postcode’,’$country’,’$ph’,’$fax’)”;
#echo “the querry prepared is:$query”;
//5.perform the SELECT operation(excute qurry)
mysql_query($query) or die(“<br/><br/><br/>insertion not possible:”); //user define error
}
//6.close the db connection
mysql_close($con);
?>
</html>
#)parameter.php
<html>
<?php
//collect the details with the same variable name
$pid=$_POST[‘pid’];
$vno=$_POST[‘vno’];
$vname=$_POST[‘vname’];
$add1=$_POST[‘add1’];
$add=$_POST[‘add’];
$city=$_POST[‘city’]; /// collect the details
$pro=$_POST[‘pro’];
$postcode=$_POST[‘postcode’];
$country=$_POST[‘country’];
$ph=$_POST[‘ph’];
$fax=$_POST[‘fax’];
if(($pid==””) &&($vno==””)) //i check the first two fields in php
{
echo “<br/><br/><font color=’blue’><h3>You Should Enter all the Details.</h3></font>”;
}
else{
//2.Connect to Mysql database from–>open connecton
$con=mysql_connect(“localhost”,”root”,””) or die(“cannot connect to MYSQL Server”);
#echo “MYSQL connection successfull”
//3.select the database(not the table)
$db=mysql_select_db(“vendor”) or die(“cannot use the database vendor”);
#echo “database part being used”;
//4.prepare an SQL querry to do insert
$query=”SELECT userid FROM vendor “;
#echo “the querry prepared is:$query”;
//5.perform the SELECT operation(excute qurry)
$rs=mysql_query($query) or die(“<br/><br/><br/>Invalid userid and password.:”);
while($row=mysql_fetch_assoc($rs))
{
foreach($row as $field)
{
if($field==””)
{
echo “<br/><br/><h4 align=’center’><font color=’red’>data not existed.</font></h4>”;
echo “<br/><br/><a href=’create.php’><h4>Back</h4></a>”;
exit(1);
}
else
echo $feild;
}
}
//6.close the db connection
mysql_close($con);
}
?>
</body>
</html>
all the forms be aline in table tag to get proper alignment
and in javascript validation will be in done regular expression
php parameter query simple print the all the data
note: if any thing not give the results plaease chech the connection parameter like action and connection parameters..