enochmh2

check user php

Dec 19th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. <?php
  2. //for connecting to the database
  3. mysql_connect("mysql7.000webhost.com","a8839106_enoch","dragon1") or
  4. die(mysql_error());
  5.  
  6. mysql_select_db("users") or die (mysql_error());
  7. //if the form has been submitted
  8. if (isset($_POST['submit'])) {
  9. //in case they leave out blank fields
  10. if (!$_POST['username'] | !$_POST['pass'] | !$_POST['email']) {
  11. die ('Please fill in all required fields');
  12. }
  13. //check if username is in use
  14. if (!get_magic_quotes_gpc()) {
  15.  
  16. $_POST['username'] = addslashes($_POST['username']); }
  17.  
  18. $usercheck= $_POST['username'];
  19. $check =mysql_query("SELECT username FROM users WHERE username= '$usercheck'")
  20.  
  21. or die("Username in use");
  22. //second check
  23. if($check2 !=0) {
  24. die ('Sorry,the username '.$_POST['username'].' is already in use.');
  25. //password encryption using md5
  26. $_POST['pass'] = md5($_POST['pass']);
  27. if (!get_magic_quotes_gpc()) {
  28. $_POST['pass'] = addslashes($_POST['pass']);
  29. $_POST['username'] = addslashes($_POST['username']);
  30. }
  31.  
  32. //inserting it in the database
  33. $insert = "INSERT INTO users (username, password)
  34. VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
  35. $add_user = mysql_query($insert);
  36.  
  37. echo "<h1> Welcome! You were successfully
  38. registered! </h1>";
  39.  
  40. echo '<h1> <a href="login.html"> Go to the signin page </a> </h1>';
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment