Advertisement
Guest User

Untitled

a guest
Aug 4th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. <?php
  2. $username = mysql_real_escape_string( $username ); //Sql injection prevention
  3. $existance = mysql_query("SELECT username FROM users WHERE username = '" . $username . "'");
  4. if( !$existance ){
  5. $query = "INSERT into `users` (username, password, email, trn_date) VALUES ('$username', '".md5($password)."', '$email', '$trn_date')";
  6. $result = mysql_query( $query );
  7. if ( $result ) {
  8. echo "<div class='form'><h3>You are registered successfully.</h3><br/>Click here to <a href='login.php'>Login</a></div>";
  9. }
  10. else{
  11. //unsuccessful insertion
  12. }
  13. } else {
  14. //the user existed already, choose another username
  15. }
  16. ?>
  17.  
  18. <?php
  19. $errorMessage = "";
  20.  
  21.  
  22.  
  23. function quote_smart($value, $handle) {
  24.  
  25. if (get_magic_quotes_gpc()) {
  26. $value = stripslashes($value);
  27. }
  28.  
  29. if (!is_numeric($value)) {
  30. $value = "'" . mysql_real_escape_string($value, $handle) . "'";
  31. }
  32. return $value;
  33. }
  34. $email = $_POST['email'];
  35. $password = $_POST['password'];
  36. $username = $_POST['username'];
  37.  
  38.  
  39. $email1 = $_POST['email'];
  40. $username1 = $_POST['username'];
  41. $password1 = $_POST['password'];
  42.  
  43. $email = htmlspecialchars($email);
  44. $password = htmlspecialchars($password);
  45. $username = htmlspecialchars($username);
  46.  
  47. $connect = mysql_connect("localhost","DBuser", "DBpassword");
  48. if (!$connect) {
  49. die(mysql_error());
  50. }
  51. mysql_select_db("DBName");
  52. $results = mysql_query("SELECT * FROM users WHERE username = '$username'");
  53. while($row = mysql_fetch_array($results)) {
  54. $kudots = $row['username']; }
  55. if ($kudots != ""){
  56. $errorMessage = "Username Already Taken";
  57. $doNothing = 1;
  58. }
  59. $result = mysql_query("SELECT * FROM users WHERE email = '$email'");
  60. while($row2 = mysql_fetch_array($results)) {
  61. $kudots2 = $row2['email']; }
  62. if ($kudots2 != ""){
  63. $errorMessage = "Email Already in use";
  64. $doNothing = 1;
  65. }
  66.  
  67. //test to see if $errorMessage is blank
  68. //if it is, then we can go ahead with the rest of the code
  69. //if it's not, we can display the error
  70.  
  71. if ($errorMessage == "") {
  72.  
  73. $user_name = "DBUsername";
  74. $pass_word = "DBPassword";
  75. $database = "DBName";
  76. $server = "localhost";
  77.  
  78. $db_handle = mysql_connect($server, $user_name, $pass_word);
  79. $db_found = mysql_select_db($database, $db_handle);
  80.  
  81. if ($db_found) {
  82.  
  83. $email = quote_smart($email, $db_handle);
  84. $password = quote_smart($password, $db_handle);
  85. $username = quote_smart($username, $db_handle);
  86.  
  87.  
  88. if ($username1 == ""){
  89. $errorMessage = "You need a username";
  90. }
  91. if ($password1 == ""){
  92. $errorMessage = $errorMessage . "<br>You need a password.";
  93. }
  94. if (!(isset($_POST['email']))){
  95. $errorMessage = $errorMessage . "<br>You need an email.";
  96. }
  97. $SQL = "SELECT * FROM users WHERE email = $email";
  98. $result = mysql_query($SQL);
  99. $num_rows = mysql_num_rows($result);
  100.  
  101. if ($num_rows > 0) {
  102. $errorMessage = "email already exists";
  103. $doNothing = 1;
  104. }
  105.  
  106.  
  107. if ($errorMessage == "") {
  108.  
  109. $SQL = "INSERT INTO users (email, username, password) VALUES ($email, $username, $password)";
  110.  
  111. $result = mysql_query($SQL);
  112.  
  113. mysql_close($db_handle);
  114.  
  115. //=================================================================================
  116. // START THE SESSION AND PUT SOMETHING INTO THE SESSION VARIABLE CALLED login
  117. // SEND USER TO A DIFFERENT PAGE AFTER SIGN UP
  118. //=================================================================================
  119. session_start();
  120. $_SESSION['email'] = "$email1";
  121. $_SESSION['password'] = "$password1";
  122.  
  123. header ("Location: myaccount.php");
  124.  
  125. else {
  126. $errorMessage = "Database Not Found";
  127. }
  128.  
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement