Guest User

Untitled

a guest
Mar 10th, 2019
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. <?php
  2.  
  3. if(!isset($_POST['username'], $_POST['password'])) {
  4. header('Location: register.html');
  5. exit();
  6. }
  7.  
  8. $servername = "localhost";
  9. $username = "or";
  10. $password = "1234";
  11. $dbname = "forum";
  12.  
  13. // Create connection
  14. $conn = new mysqli($servername, $username, $password, $dbname);
  15. // Check connection
  16. if ($conn->connect_error) {
  17. die("Connection failed: " . $conn->connect_error);
  18. }
  19.  
  20. $sql = "INSERT INTO users (username, password) VALUES ('".$_POST['username']."', '".$_POST['password']."')";
  21.  
  22. if ($conn->query($sql) === TRUE) {
  23. echo "New record created successfully";
  24. } else {
  25. echo "Error: ".$sql."<br>".$conn->error;
  26. }
  27.  
  28. $conn->close();
  29.  
  30. // Eventually redirect to index
  31. header('Location: index.php');
  32.  
  33. ?>
Add Comment
Please, Sign In to add comment