Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. <form method='post' action='re.php'>
  2.  
  3. <form method='post' action='<?php echo $_SERVER["PHP_SELF"];?>'>
  4.  
  5. <?php
  6.  
  7. $hostname = 'localhost';
  8. $username = 'Ciara';
  9. $password = 'mypass';
  10. $database = 'users';
  11.  
  12. $conn = mysqli_connect($hostname,$username, $password, $database);
  13. if (!$conn) {
  14. die ("Databas connect failed: " . mysqli_connect_error());
  15. } else {
  16. echo "Connected successfully. <br>";
  17. }
  18.  
  19. echo <<<_END
  20. <html>
  21. <head>
  22. <title>Register</title>
  23. </head>
  24. <body><center>
  25. <form method='post' action='<?php echo $_SERVER["PHP_SELF"];?>'>
  26. Firstname: <input type='text' name='firstname'><br>
  27. Lastname: <input type='text' name='lastname'><br>
  28. E-mail: <input type='text' name='email'><br>
  29. Gender: <input type='radio' value='female' name='gender'>Female
  30. <input type='radio' value='male' name='gender'>Male<br>
  31. Username: <input type='text' name='username'><br>
  32. Password: <input type='text' name='password'><br>
  33. <input type='submit' value='Submit Form'>
  34. </form></center>
  35.  
  36. _END;
  37.  
  38. if (isset($_POST['firstname']) &&
  39. isset($_POST['lastname']) &&
  40. isset($_POST['email']) &&
  41. isset($_POST['gender']) &&
  42. isset($_POST['username']) &&
  43. isset($_POST['password'])) {
  44.  
  45. $firstname = get($conn, 'firstname');
  46. $lastname = get($conn, 'lastname');
  47. $email = get($conn, 'email');
  48. $gender = get($conn, 'gender');
  49. $username = get($conn, 'username');
  50. $password = get($conn, 'password');
  51.  
  52. $query = "insert into useracc values" . "(null, '$firstname','$lastname','$email','$gender','$username','$password')";
  53.  
  54. if (mysqli_query($conn, $query)) {
  55. echo "You have successfully registered! <br>";
  56. } else {
  57. echo "Failed to register." . mysqli_error($conn);
  58. }
  59. }
  60.  
  61. mysqli_close($conn);
  62. echo "</body></html>";
  63.  
  64. function get($conn, $var) {
  65. return mysqli_real_escape_string($conn, $_POST[$var]);
  66. }
  67. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement