Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write Code in PHP Signup form contains: email address, password (6 characters at

ID: 3666485 • Letter: W

Question

Write Code in PHP Signup form contains: email address, password (6 characters at least), full name (required), zip code (5 digit number) and valid US phone number signup application by adding the following features: 1. Store the customer information to the MySQL database. You will need to write a script called customerdb.sql to create a new database and a customer table. 2. Create a PHP file called db_connect.php to create a PDO connection object to the MySQL database. 3. Enhance the signup.php by adding PHP code to the value attribute of the input element so the inputs can be retained in case the signup.php needs to be reloaded again. Example, 4. Complete the addcustomer.php by adding the followings: • Add the data validation code to validate email address, password (6 characters at least), full name (required), zip code (5 digit number) and valid US phone number. • Use filter_input() function to filter invalid inputs. Example:

<?php

// Get the book info

$publisher_id = filter_input(INPUT_POST, 'publisher_id', FILTER_VALIDATE_INT);

$isbn = filter_input(INPUT_POST, 'isbn');

$title = filter_input(INPUT_POST, 'book_title');

$price = filter_input(INPUT_POST, 'book_price', FILTER_VALIDATE_FLOAT);

// Validate inputs

if ($publisher_id == null || $publisher_id == false ||

$isbn == null || $title == null || $price == null || $price == false) {

$error_msg = 'Invalid input data';

include(' addbook_form.php');

exit(1);

}

• Add the code to insert the new customer information to the database.

Explanation / Answer


Can help you with this any more information needed please comment

<!DOCTYPE html PUBLIC "-//DTD XHTML 1.0 Strict//EN".dtd">
<html xmlns="http:" lang="en" xml:lang="en">
<head>
<title>Validating User Input.</title>
<style type="text/css">
<!--
label,input
{
display: block;
width: 150px;
float: left;
margin-bottom: 10px;
}
label
{
text-align: right;
width: 75px;
padding-right: 20px;
}
br
{
clear: left;
}
-->
</style>
</head>
<body>
<h3>* denotes required field!</h3>
<form action="<?php echo htmlentities( $_SERVER['PHP_SELF'] );?>" method="post">
<p>
<label for="name">Name</label>
<input id="name" type="text" name="userName" maxlength="25" />*<br />
<label for="address">Address</label>
<input id="address" type="text" name="userAddress" maxlength="100" /><br />
<label for="city">City</label>
<input id="city" type="text" name="userCity" maxlength="25" /><br />
<label for="zip">Zip</label>
<input id="zip" type="text" name="userZip" maxlength="5" /><br />
<label for="email">Email</label>
<input id="email" type="text" name="userEmail" maxlength="50" />*<br />
<label for="submit">Submit</label>
<input id="submit" type="submit" value="Mail It!" /><br />
</p>
</form>
<?php
function sanityCheck($string, $type, $length){
$type = 'is_'.$type;
if(!$type($string))
{
return FALSE;
}
elseif(empty($string))
{
return FALSE;
}
elseif(strlen($string) > $length)
{
return FALSE;
}
else
{
return TRUE;
}
}
function checkSet()
{
return isset($_POST['userName'], $_POST['userAddress'], $_POST['userCity'], $_POST['userZip'], $_POST['userEmail']);
}
function checkNumber($num, $length)
{
if($num > 0 && strlen($num) == $length)
{
return TRUE;
}
}
function checkEmail($email)
{
return preg_match('/^S+@[wd.-]{2,}.[w]{2,6}$/iU', $email) ? TRUE : FALSE;
}
if(checkSet() != FALSE)
{
if(empty($_POST['userName'])==FALSE && sanityCheck($_POST['userName'], 'string', 25) != FALSE)
{
//If all is well we can assign the value of POST field to a variable
$userName = $_POST['userName'];
}
else
{
echo 'Username is not set';
exit();
}
if(sanityCheck($_POST['userAddress'], 'string', 100) != FALSE)
{
$userAddress = $_POST['userAddress'];
}
else
{
$userAddress = '';
}
if(sanityCheck($_POST['userCity'], 'string', 25) != FALSE)
{
$userCity = $_POST['userCity'];
}
else
{
$userCity = '';
}
if(sanityCheck($_POST['userZip'], 'numeric', 5) != FALSE && checkNumber($_POST['userZip'], 5) == TRUE)
{
$userZip = $_POST['userZip'];
}
else
{
$userZip='';
}
if(sanityCheck($_POST['userEmail'], 'string', 5) != FALSE && checkEmail($_POST['userEmail']) != FALSE)
{
$userEmail = $_POST['userEmail'];
}
else
{
echo 'Invalid Email Address Supplied';
exit();
}
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link)
{
die('Not connected : ' . mysql_error());
}
$db_selected = mysql_select_db('test', $link);
if (!$db_selected)
{
die ("Database not selected : " . mysql_error());
}
$query = sprintf("INSERT INTO people (userName, userAddress, userCity, userZip, userEmail)
VALUES( '%s', '%s','%s','%s','%s')",
mysql_real_escape_string($userName),
mysql_real_escape_string($userAddress),
mysql_real_escape_string($userCity),
mysql_real_escape_string($userZip),
mysql_real_escape_string($userEmail));
if(!mysql_query($query))
{
echo 'Query failed '.mysql_error();
exit();
}
else
{
$subject = 'Submission';
$msg= 'Thank you for submitting your information';
if(!mail($userEmail,$subject,$msg, "From: $userEmail Reply-To: $userEmail X-Mailer: PHP/" . phpversion()))
{
echo 'Unable to send confirmation mail';
}
else
{
echo 'Thank you for your submission, a confirmation email has bee sent to '.$userEmail;
}
}
}
else
{
echo '<p>Please fill in the form above</p>';
}
?>
</body>
</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote