Guest
Public paste!

Untitled

By: a guest | Mar 20th, 2010 | Syntax: PHP | Size: 2.63 KB | Hits: 52 | Expires: Never
Copy text to clipboard
  1. <?php
  2.  
  3.  
  4.  
  5.  
  6.     //Access database connection.
  7.  
  8.     //Get customer's contact details from form. Sends information to customer table
  9.  
  10.     $customerFirstName = $_POST['customerFirstName'];
  11.     $customerLastName = $_POST['customerLastName'];
  12.     $customerAddress = $_POST['customerAddress'];
  13.     $customerPhonenumber = $_POST['customerPhonenumber'];
  14.     $customerEmailAddress = $_POST['customerEmailAddress'];
  15.  
  16.     //Get customer's desired login details from form. Sends information to user table      
  17.  
  18.     $userName = $_POST['userName'];
  19.     $userPassword = $_POST['userPassword'];
  20.     $userRepassword= $_POST['userRepassword'];
  21.     //Insert user data into user table.
  22.     //include
  23. $customerphoneNumber = ereg_replace("[^0-9]", "", $customerphoneNumber);    
  24.  
  25.     if (($userName == "") or ($customerFirstName == "") or ($customerLastName=="") or ($customerAddress == "") or ($customerPhonenumber=="") or ($customerEmailAddress=="") or ($userPassword==""))
  26. {
  27.     echo"<p>Fields missing, all fields must be completed</p>";
  28. }
  29. elseif (!(strstr($customerEmailAddress, "@")) or !(strstr($customerEmailAddress, ".")))
  30. {
  31.     echo"<p>Invalid Email Address, must contain an '@' an a '.' </p>";
  32. }
  33. elseif ($userPassword != $userRepassword)
  34. {
  35.     echo"<p>Password Miss Match! pleaase re-enter</p>";
  36. }
  37. else
  38. {
  39. require_once('dbconnection.php');
  40. }
  41.     $addCustomer="INSERT INTO customer (customerFirstName, customerLastName, customerAddress, customerPhonenumber, customerEmailAddress)
  42.    VALUES ('$customerFirstName', '$customerLastName', '$customerAddress', '$customerPhonenumber', '$customerEmailAddress')";
  43.              
  44.     if(@mysql_query($addCustomer))
  45.     {
  46.  
  47.         //If customer submits a user name.
  48.  
  49.         if(isset($userName))
  50.         {
  51.  
  52.             //Get user ID (customerID(FK))
  53.  
  54.             $customerID=mysql_insert_id();
  55.  
  56.             //Insert the user details.
  57.  
  58.             $addUser="INSERT INTO user (userID, userName, userPassword, customerID)
  59.  
  60.            VALUES (NULL, '$userName', '$userPassword', $customerID)";
  61.  
  62.             $addResult=mysql_query($addUser);
  63.  
  64.         }            
  65.  
  66.         // Display first name and user name - Used to check if customer was added correctly.
  67.  
  68.         echo "Cheers ".$customerFirstName." your user name is: ".$userName."<br>";  
  69.  
  70.         echo("<p>Customer Added.</p>");
  71.     }    
  72.     else
  73.  
  74.     {      
  75.         echo("<p>Error adding customer: </p>".mysql_error()."</p>");
  76.     }
  77. ?>
  78. <html>
  79.     <body>
  80.         <a href="registration.html">Go back to registration form</a>
  81.         <br><br>
  82.          <a href="index.php">Go back to login form</a>  
  83.     </body>
  84. </html>