Guest User

Untitled

a guest
Oct 3rd, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. <?php
  2. //start new session
  3. session_start ();
  4.  
  5. /**
  6. * Author: Adam Scheidler
  7. * Date: 3/30/2012
  8. * Description: This script writes a new user information into the database
  9. */
  10.  
  11.  
  12. //set page title
  13. $page_title = "Create a new user account";
  14.  
  15. //include code from header.php and database.php
  16.  
  17. require_once('includes/database.php');
  18.  
  19. //retrieve user inputs from the form
  20. $firstname = $_POST['firstname'];
  21. $lastname = $_POST['lastname'];
  22. $username = $_POST['username'];
  23. $password = $_POST['password'];
  24. $role = 2; //regular user
  25.  
  26. //insert statement. The id field is an auto field.
  27. $query_str = "INSERT INTO users VALUES (NULL, '$firstname', '$lastname', '$username', '$password', '$role')";
  28.  
  29. //execut the insert query
  30. $result = @$conn->query($query_str);
  31.  
  32. //Handle selection errors
  33. if (!$result) {
  34. $errno = $conn->errno;
  35. $errmsg = $conn->error;
  36. echo "Insertion failed with: ($errno) $errmsg<br/>\n";
  37. $conn->close();
  38. exit;
  39. }
  40. $conn->close();
  41.  
  42. //create session variables
  43. $_SESSION['login'] = $username;
  44. $_SESSION['name'] = $firstname . " " . $lastname;
  45. $_SESSION['role'] = 2;
  46.  
  47.  
  48. //set login status to 3 since this is a new user.
  49. $login_status=3;
  50.  
  51.  
  52.  
  53. //redirect the user to the loginform.php page
  54. header("Location: loginform.php?ls=$login_status");
  55.  
  56. ?>
Add Comment
Please, Sign In to add comment