Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. <a href="index.php">Index</a><br>
  2. <form name="registrationForm" method="post" onsubmit="return validateForm()">
  3. <input type="text" class="form-control" placeholder="Enter username" name="username"><font color="red">*</font>
  4. <input type="text" class="form-control" placeholder="Enter email address" name="email"><font color="red">*</font>
  5. <input type="password" class="form-control" placeholder="Enter password" name="password"><font color="red">*</font>
  6. <input type="text" class="form-control" placeholder="Enter first name" name="first"><font color="red">*</font>
  7. <input type="text" class="form-control" placeholder="Enter last name" name="last"><font color="red">*</font>
  8. <input type="text" class="form-control" placeholder="Enter zip code" name="zip"><font color="red">*</font>
  9. <input class="btn btn-default" type="submit" name="submit" value="Submit">
  10. </form>
  11.  
  12. <?php
  13. ini_set('display_errors',1);
  14. error_reporting(E_ALL);
  15.  
  16. if (isset($_POST['submit'])){
  17. //if($_SERVER["REQUEST_METHOD"] == "POST"){
  18. $username = $_POST["username"];
  19. $email = $_POST["email"];
  20. $password = $_POST["password"];
  21. $first = $_POST["first"];
  22. $last = $_POST["last"];
  23. $zip = $_POST["zip"];
  24.  
  25. // Check connection
  26. if ($db->connect_error) {
  27. die("Connection failed: ".$db->connect_error);
  28. }
  29.  
  30. //flag to detect if the username exists in db
  31. $flag = 0;
  32. $sql = "SELECT username FROM users WHERE username = '".$username."';";
  33. $result = $db->query($sql);
  34. if ($result->num_rows > 0) {
  35. $flag = 1;
  36. }
  37.  
  38. //If the username already exists then alert the user, else insert the record to the db and send user to login.php
  39. if ($flag == 1){
  40. echo "<script>alert("Sorry, that username is already taken. Please choose another.");</script>";
  41. }
  42. else {
  43. $sql = "INSERT INTO users (first, last, username, email, password, zip) VALUES ('".$first."', '".$last."', '".$username."', '".$email."', '".$password."', '".$zip."')";
  44. if ($db->query($sql) === TRUE) {
  45. //echo "Registration successful";
  46. //$filename = "/profiles/".$username.".php";
  47. //chmod($filename,0777);
  48. echo 'Current script owner: ' . get_current_user() . "<br>";
  49. echo 'posix: '.posix_getuid()."<br>";
  50. echo getcwd()."<br>";
  51. $last_line = system('whoami', $retval);
  52. echo $last_line . " " . $retval;
  53. $file = fopen("profiles/test.txt", "w") or die("Unable to open file!");
  54. //$txt = "This is a user profile for ".$username;
  55. //fwrite($file, $txt);
  56. fclose($file);
  57. //header('Location: login.php');
  58. } else {
  59. echo "Registration error, please try again later.";
  60. }
  61. }
  62. }
  63. $db->close();
  64. ?>
  65. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement