<?php
//Access database connection.
//Get customer's contact details from form. Sends information to customer table
$customerFirstName = $_POST['customerFirstName'];
$customerLastName = $_POST['customerLastName'];
$customerAddress = $_POST['customerAddress'];
$customerPhonenumber = $_POST['customerPhonenumber'];
$customerEmailAddress = $_POST['customerEmailAddress'];
//Get customer's desired login details from form. Sends information to user table
$userName = $_POST['userName'];
$userPassword = $_POST['userPassword'];
$userRepassword= $_POST['userRepassword'];
//Insert user data into user table.
//include
$customerphoneNumber = ereg_replace("[^0-9]", "", $customerphoneNumber);
if (($userName == "") or ($customerFirstName == "") or ($customerLastName=="") or ($customerAddress == "") or ($customerPhonenumber=="") or ($customerEmailAddress=="") or ($userPassword==""))
{
echo"<p>Fields missing, all fields must be completed</p>";
}
elseif (!(strstr($customerEmailAddress, "@")) or !(strstr($customerEmailAddress, ".")))
{
echo"<p>Invalid Email Address, must contain an '@' an a '.' </p>";
}
elseif ($userPassword != $userRepassword)
{
echo"<p>Password Miss Match! pleaase re-enter</p>";
}
else
{
require_once('dbconnection.php');
}
$addCustomer="INSERT INTO customer (customerFirstName, customerLastName, customerAddress, customerPhonenumber, customerEmailAddress)
VALUES ('$customerFirstName', '$customerLastName', '$customerAddress', '$customerPhonenumber', '$customerEmailAddress')";
if(@mysql_query($addCustomer))
{
//If customer submits a user name.
if(isset($userName))
{
//Get user ID (customerID(FK))
$customerID=mysql_insert_id();
//Insert the user details.
$addUser="INSERT INTO user (userID, userName, userPassword, customerID)
VALUES (NULL, '$userName', '$userPassword', $customerID)";
$addResult=mysql_query($addUser);
}
// Display first name and user name - Used to check if customer was added correctly.
echo "Cheers ".$customerFirstName." your user name is: ".$userName."<br>";
echo("<p>Customer Added.</p>");
}
else
{
echo("<p>Error adding customer: </p>".mysql_error()."</p>");
}
?>
<html>
<body>
<a href="registration.html">Go back to registration form</a>
<br><br>
<a href="index.php">Go back to login form</a>
</body>
</html>