Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. <?
  2. /**
  3.  * Process.php
  4.  */
  5.  
  6. include("database.php");
  7.  /** process form */
  8. /** really shouldnt use posts but u can always sanitize them */
  9.  
  10. $subuser = $_POST["username"];
  11. $subfirst = $_POST["firstname"];
  12. $subsurname = $_POST["surname"];
  13. $subpassword = $_POST["password"];
  14.  
  15. function usernameTaken($username){
  16.       $q = "SELECT username FROM ".TBL_USERS." WHERE username = '$username'";
  17.       $result = mysql_query($q);
  18.       return (mysql_num_rows($result) > 0);
  19.    }
  20.  
  21.  
  22.     /* check username is taken */
  23.  
  24. /* username is not in use so we add it to database */
  25. if (usernameTaken($subuser) == 0 ) {
  26.  
  27.     $q = mysql_query ("INSERT INTO information (username, firstname, surname, password) VALUES ('$subuser', '$subfirst', '$subsurname', '$subpassword')");  echo mysql_error();
  28.     $success = 1;
  29.     if ($success == 1) { echo "User ".$subuser." Added"; }
  30.     }
  31.  
  32. /* username is in use so we tell user and re-display form */
  33. else if (usernameTaken($subuser) > 0 ) {
  34.     echo "User ".$subuser." already exists, choose another username";
  35.     header('Refresh:3; URL= informationform.php');
  36.         }
  37.  
  38.  
  39. ?>
  40.  
  41.  
  42. <a href="display_users.php">Show Users</a><br / >
  43. <a href="informationform.php">Add a new user</a>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement