Advertisement
devilyouknow

Untitled

Mar 29th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. <?php
  2. $serverName = "127.0.0.1"; //address for MySQL server
  3. $user = "***";
  4. $pass = "***";
  5. $dbName ="***";
  6. $fname = ($_POST["firstName"]);
  7. $lname = ($_POST["lastName"]);
  8. $address = ($_POST["add"]);
  9. $loccity = ($_POST["city"]);
  10. $locstate = ($_POST["state"]);
  11. $zcode = ($_POST["zip"]);
  12. $telephone = ($_POST["phoneNumber"]);
  13. $subemail = ($_POST["email"]);
  14. $user_chars = "#[^a-zA-Z0-9_\-]#";
  15. $email_chars = "/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/";
  16. function errorMsg()
  17. {
  18. $con = mysql_connect('*********');
  19. if (!$con)
  20. {
  21. die('Could not connect: ' . mysql_error());
  22. }
  23. else
  24. {
  25. if (!empty($_POST))
  26. {
  27. if ((empty($_POST["firstName"]))||(empty($_POST["lastName"]))||(empty($_POST["add"]))||(empty($_POST["city"]))||(empty($_POST["zip"]))||(empty($_POST["phoneNumber"]))||(empty($_POST["email"])))
  28. {
  29. die('Some fields were missing; go <a href="register.php">back here</a> and start again.');
  30. }
  31. else
  32. {
  33. $DB_DB ="***";
  34. $FNAME = ($_POST["firstName"]);
  35. $LNAME = ($_POST["lastName"]);
  36. $ADDRESS = ($_POST["add"]);
  37. $LOCCITY = ($_POST["city"]);
  38. $LOCSTATE = ($_POST["state"]);
  39. $ZCODE = ($_POST["zip"]);
  40. $TELEPHONE = ($_POST["phoneNumber"]);
  41. $SUBEMAIL = ($_POST["email"]);
  42. $user_chars = "#[^a-zA-Z0-9_\-]#";
  43. $email_chars = "/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/";
  44. $FORMAT = ($_POST["optIn"]);
  45. if (strlen($ZCODE) != 5) // check zip code
  46. {
  47. die('Invalid zip code; go <a href="register.php">back here</a> and start again.');
  48. }
  49. if (strlen($TELEPHONE) <= 9) // check phone number
  50. {
  51. die('Invalid phone number; go <a href="register.php">back here</a> and start again.');
  52. }
  53. if (strlen($TELEPHONE) >= 18) // check phone number
  54. {
  55. die('Invalid phone number; go <a href="register.php">back here</a> and start again.');
  56. }
  57. if(preg_match($user_chars,$FNAME)) // check first name
  58. {
  59. die('Invalid first name; go <a href="register.php">back here</a> and start again.');
  60. }
  61. if(preg_match($user_chars,$LNAME))// check last name
  62. {
  63. die('Invalid last name; go <a href="register.php">back here</a> and start again.');
  64. }
  65. if(preg_match($user_chars,$LOCCITY))// check city
  66. {
  67. die('Invalid city; go <a href="register.php">back here</a> and start again.');
  68. }
  69. else
  70. {
  71. unset($qry);
  72. $SUBEMAIL = mysql_real_escape_string($SUBEMAIL);
  73. $register_sql = "insert into " . mysql_real_escape_string($DB_DB) . ".marketing (fname,lname,address,loccity,locstate,zcode,telephone,format,subemail) values ('" . $FNAME . "','" . $LNAME . "','" . $ADDRESS . "','" . $LOCCITY . "','" . $LOCSTATE . "','" . $ZCODE . "','" . $TELEPHONE . "','" . $FORMAT . "','" . $SUBEMAIL . "')";
  74. $qry = @mysql_query($register_sql, $con);
  75. if (!$qry)
  76. {
  77. die("Error creating account: " . mysql_error());
  78. }
  79. else{
  80. if (FORMAT == "1") // opt in for flyer
  81. {
  82. echo 'Thank you for signing up for our flyer!<br />';
  83. }
  84. if ($FORMAT == "2") //opt in for email
  85. {
  86. echo 'Thank you for signing up for our email!<br />';
  87. }
  88. else // opt in for email and flyer
  89. {
  90. echo 'Thank you for signing up for our email and flyer!<br />';
  91. }
  92. }
  93. }
  94. }
  95. }
  96. }
  97. }
  98. errorMsg(); // Write function
  99. mysql_close($con); // terminate MySQL connection
  100. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement