Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. <?php
  2. include("include/config.php");
  3.  
  4.  
  5. //Function to sanitize values received from the form. Prevents SQL injection
  6. function clean($str) {
  7. $str = @trim($str);
  8. if(get_magic_quotes_gpc()) {
  9. $str = stripslashes($str);
  10. }
  11. return mysql_real_escape_string($str);
  12. }
  13.  
  14. //Sanitize the POST values
  15.  
  16. $email = clean($_POST['email']);
  17. $username = clean($_POST['username']);
  18. $password = clean($_POST['password']);
  19. $cpassword = clean($_POST['cpassword']);
  20.  
  21. //Input Validations
  22.  
  23. if($email == '') {
  24. $errmsg_arr[] = 'Email missing';
  25. }
  26. if($login == '') {
  27. $errmsg_arr[] = 'Login ID missing';
  28. }
  29. if($password == '') {
  30. $errmsg_arr[] = 'Password missing';
  31. }
  32. if($cpassword == '') {
  33. $errmsg_arr[] = 'Confirm password missing';
  34. }
  35. if( strcmp($password, $cpassword) != 0 ) {
  36. $errmsg_arr[] = 'Passwords do not match';
  37. }
  38.  
  39. //Check for duplicate login ID
  40. if($login != '') {
  41. $qry = "SELECT * FROM c4c_members WHERE username='$username'";
  42. $result = mysql_query($qry);
  43. if($result) {
  44. if(mysql_num_rows($result) > 0) {
  45. $errmsg_arr[] = 'Login ID already in use';
  46. }
  47. @mysql_free_result($result);
  48. }
  49. else {
  50. die("Query failed2");
  51. }
  52. }
  53.  
  54. //If there are input validations, redirect back to the registration form
  55. if($errflag) {
  56. $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
  57. session_write_close();
  58. header("location: register.php");
  59. exit();
  60. }
  61.  
  62. //Create INSERT query
  63. $qry = "INSERT INTO c4c_members(email, username, pass) VALUES('$email','$username','".md5($_POST['password'])."')";
  64. $result = @mysql_query($qry);
  65.  
  66. //Check whether the query was successful or not
  67. if($result) {
  68. header("location: login.php");
  69. exit();
  70. }else {
  71. die("Query failed1");
  72. }
  73. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement