/php/business_register_exec.php

https://bitbucket.org/isanneh/campus-pages · PHP · 185 lines · 132 code · 39 blank · 14 comment · 37 complexity · ddf1a23177057812f4ffae63f8e0a22b MD5 · raw file

  1. <?php
  2. //Start session
  3. session_start();
  4. //Include database connection details
  5. //require_once('connect.php');
  6. include("connect.php");
  7. //Array to store validation errors
  8. $errmsg_arr = array();
  9. //Validation error flag
  10. $errflag = false;
  11. //Function to sanitize values received from the form. Prevents SQL injection
  12. function clean($str) {
  13. $str = @trim($str);
  14. if(get_magic_quotes_gpc()) {
  15. $str = stripslashes($str);
  16. }
  17. return mysql_real_escape_string($str);
  18. }
  19. //email format
  20. function isValidEmail($email){
  21. return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);
  22. }
  23. //name format
  24. function isValidName($name){
  25. return eregi ("^[a-zA-Z][a-zA-Z -]*$", $name);
  26. }
  27. //Sanitize the POST values
  28. $business_name = clean($_POST['business_name']);
  29. $business_category = clean($_POST['business_category']);
  30. $other_category = clean($_POST['other_category']);
  31. $phone = clean($_POST['phone']);
  32. $fax = clean($_POST['fax']);
  33. $website = clean($_POST['website']);
  34. $street = clean($_POST['street']);
  35. $borough = clean($_POST['borough']);
  36. $zipcode = clean($_POST['zipcode']);
  37. $email_address = clean($_POST['email_address']);
  38. $user_name = clean($_POST['user_name']);
  39. $password = clean($_POST['password']);
  40. $confirm_password = clean($_POST['confirm_password']);
  41. $description = clean($_POST['description']);
  42. //Input Validations
  43. if($business_name == '') {
  44. $errmsg_arr[] = 'Business name missing';
  45. $errflag = true;
  46. }
  47. if($business_category == 'choose_business_category' && $other_category == '' ) {
  48. $errmsg_arr[] = 'Category missing';
  49. $errflag = true;
  50. }
  51. else
  52. {
  53. if($business_category == 'choose_business_category') {
  54. $chosen_category=$other_category;
  55. }
  56. else
  57. {
  58. if($other_category == '' ) {
  59. $chosen_category=$business_category;
  60. }
  61. }
  62. }
  63. if($phone == '') {
  64. $errmsg_arr[] = 'Phone missing';
  65. $errflag = true;
  66. }
  67. if($street == '') {
  68. $errmsg_arr[] = 'Street missing';
  69. $errflag = true;
  70. }
  71. if($borough == 'choose_borough') {
  72. $errmsg_arr[] = 'Borough missing';
  73. $errflag = true;
  74. }
  75. if($zipcode == '') {
  76. $errmsg_arr[] = 'Zipcode missing';
  77. $errflag = true;
  78. }
  79. if($email_address == '') {
  80. $errmsg_arr[] = 'Email missing';
  81. $errflag = true;
  82. }
  83. else
  84. {
  85. if(isValidEmail($email_address) ==TRUE)
  86. {
  87. }
  88. else
  89. {
  90. $errmsg_arr[] = 'Email address is not valid';
  91. $errflag = true;
  92. }
  93. }
  94. if($user_name == '') {
  95. $errmsg_arr[] = 'Login ID missing';
  96. $errflag = true;
  97. }
  98. if($password == '') {
  99. $errmsg_arr[] = 'Password missing';
  100. $errflag = true;
  101. }
  102. if($confirm_password == '') {
  103. $errmsg_arr[] = 'Confirm password missing';
  104. $errflag = true;
  105. }
  106. if( strcmp($password, $confirm_password) != 0 ) {
  107. $errmsg_arr[] = 'Passwords do not match';
  108. $errflag = true;
  109. }
  110. //Check for duplicate login ID
  111. if($login != '') {
  112. $qry = "SELECT * FROM users WHERE UserName='$user_name'";
  113. $result = mysql_query($qry);
  114. if($result) {
  115. if(mysql_num_rows($result) > 0) {
  116. $errmsg_arr[] = 'Login ID already in use';
  117. $errflag = true;
  118. }
  119. @mysql_free_result($result);
  120. }
  121. else {
  122. die("Query failed");
  123. }
  124. }
  125. //If there are input validations, redirect back to the registration form
  126. if($errflag) {
  127. $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
  128. session_write_close();
  129. header("location: business_registration.php");
  130. exit();
  131. }
  132. $state= 'NY';
  133. $country= 'United States';
  134. //Create INSERT query
  135. $qry = "INSERT INTO Business(Business_Name, Category, Street, City, State, Country, Zipcode, Description, Website, Phone, Fax, User_Name, Email_Address, Password) VALUES('$business_name', '$chosen_category', '$street', '$borough', '$state', '$country', '$zipcode', '$description', '$website', '$phone', '$fax', '$user_name', '$email_address','".md5($_POST['password'])."')";
  136. $result = @mysql_query($qry);
  137. //Check whether the query was successful or not
  138. if($result) {
  139. $_SESSION['SESS_USERNAME'] = $user_name;
  140. $_SESSION['SESS_EMAILADDRESS'] = $email_address;
  141. header("location: payment.php");
  142. exit();
  143. }else {
  144. die("Query failed");
  145. }
  146. ?>