a 10 points Create a PHP page to read one name Add input val
a) (10 points) Create a PHP page to read one name. Add input validation such that the name is required, and only contains letters and white space. You do not have to modify the input. You only have to alert the user of the inappropriate use of special characters, and give him or her another chance to enter the name.
$nameErrMsg=\"\";
$names=\"\";
if($_SERVER [\"REQUESTED METHOD\"]==\"POST\")
{
if (empty ($_POST[\"NAME\"]))
{
$nameErrMsg=\"Requiring a Name\";
}
else
{
$names=test_input ($_POST [\"NAME\"]);
if(!preg_match(\"/^[a-zA-z ]*$/\",$names))
{
$namesErrMsg=\"allowing letters and whitespaces only\";
}
}
?>
b) (15 points) Upon submission: Print out the complete row for a person in the customer table from assignment 2, that has as lastName the name that was entered.
Use the information from the in-class demos on integrating PHP into MySQL to help build your database integration
THIS is the assignment 2 Code that is NEEDED to answer B) :
CREATE TABLE `jasocook_366f16`.`Employee` (
`eID` INT NOT NULL,
`fName` VARCHAR(45) NULL,
`lName` VARCHAR(45) NULL,
`zip` INT NULL,
PRIMARY KEY (`eID`));
CREATE TABLE `jasocook_366f16`.`Telephone` (
`tID` INT NOT NULL,
`eID` INT NULL,
`tNumber` INT NULL,
PRIMARY KEY (`tID`),
foreign key (eID) references Employee(eID));
CREATE TABLE `jasocook_366f16`.`Customer` (
`cID` INT NOT NULL,
`fName` VARCHAR(45) NULL,
`lName` VARCHAR(45) NULL,
`street` VARCHAR(50) NULL,
`city` VARCHAR(100) NULL,
`zip` INT NULL,
PRIMARY KEY (`cID`));
CREATE TABLE `jasocook_366f16`.`Part` (
`pID` INT NOT NULL,
`pName` VARCHAR(1000) NULL,
`price` INT NULL,
`quantity` INT NULL,
PRIMARY KEY (`pID`));
CREATE TABLE `jasocook_366f16`.`Orders` (
`oID` INT NOT NULL,
`recieveDate` DATE NULL,
`shipDate` DATE NULL,
`cID` INT NULL,
`eID` INT NULL,
PRIMARY KEY (`oID`),
foreign key (cID) references Customer(cID),
foreign key (eID) references Employee(eID));
CREATE TABLE `jasocook_366f16`.`PartOrder` (
`pOID` INT NOT NULL,
`pID` INT NULL,
`oID` INT NULL,
`quantity` INT NULL,
PRIMARY KEY (`pOID`),
foreign key (pID) references Part(pID),
foreign key (oID) references Orders(oID));
insert into Employee values(1,\'Jason\',\'Cook\', 58104);
insert into Employee values(2,\'Alison\',\'Olson\',58104);
insert into Telephone values(1,1,1234567891);
insert into Telephone values(2,2,234567891);
insert into Customer values(1,\'Pam\',\'Wiseman\', \'123 West Palm St.\',\'Chicago\',23456);
insert into Customer values(2,\'John\',\'Wayne\', \'123 Bang Bang St.\',\'Austin\',55555);
insert into Part values(1,\'Part1\', 120, 2);
insert into Part values(2,\'Part2\', 500, 2);
insert into Orders values(1,\'2016-09-10\',\'2016-28-09\',(SELECT cID from Customer where cID=1),(Select eID from Employee where eID=1));
insert into Orders values(2,\'2016-09-10\',\'2016-30-09\',(select cID from Customer where cID=2),(select eID from Employee where eID=2));
insert into PartOrder values(1,(select pID from Part where pID=1),(select oID from Orders where oID=1),1);
insert into PartOrder values(2,(select pID from Part where pID=2),(select oID from Orders where oID=2),1);
select *
from Employee;
select *
from Customer;
select *
from Part;
select*
from Orders;
select *
from PartOrder;
select *
from Orders
inner join Customer
on Orders.cID=Customer.cID;
select *
from Employee
inner join Orders
on Employee.eID=Orders.eID;
DELETE from PartOrder
where pOID in select(
Part.pOID
from PartOrder, Orders
on Orders.oID = Part.oID
where Orders.shipDate < SYSDATE);
alter table PartOrder add Processed int;
CREATE VIEW [view1] AS
SELECT Part.pID, Part.quantity
FROM Part JOIN PartOrder ON Part.pID = PartOrder.pID
WHERE PartOrder.oID IN (SELECT oID FROM Orders WHERE YEAR(rDate) = 2016 );
Solution
A)
<html>
<head><title> Sample </title></head>
<body>
<?php>
$nameErrMsg=\"\";
$names=\"\";
if($_SERVER [\"REQUESTED METHOD\"]==\"POST\")
{
if (empty ($_POST[\"NAME\"]))
{
$nameErrMsg=\"Requiring a Name\";
}
else
{
$names=test_input ($_POST [\"NAME\"]);
if(!preg_match(\"/^[a-zA-z ]*$/\",$names))
{
$namesErrMsg=\"allowing letters and whitespaces only\";
}
}
echo \'<script language=\"javascript\">\';
echo \"alert(\'$namesErrMsg\')\";
echo \'</script>\';
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<form method=\"post\" action=\"<?php echo htmlspecialchars($_SERVER[\"PHP_SELF\"]);?>\">
Name:<input type=\"text\" name=\"NAME\" value=\"\"/>
</form>
</body>
</html>


