Guest User

Untitled

a guest
Feb 18th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. <html>
  2. <form action ="/Testando/dbconnect" method="post">
  3. <h1>Entrar e Inserir Dados</h1>
  4. <br>
  5. <p>Introduza os seguintes dados:</p><br>
  6. Nome: <input type = "text" name= "Nome">
  7. Idade: <input type = "text" name= "Morada"><br>
  8. Género: <select name="Gender">
  9. <option value="homem">Homem</option>
  10. <option value="mulher">Mulher</option>
  11. </select><br><br>
  12. <input type = "submit" value = "Submit Me"><br>
  13. <input type="reset">
  14. </html>
  15.  
  16. <?php
  17. $servername = "localhost";
  18. $username = "root";
  19. $password = "";
  20. $dbname = "test";
  21.  
  22. $conn = mysqli_connect($servername, $username, $password, $dbname);
  23. if (!$conn) {
  24. die("Connection failed: " . mysqli_connect_error());
  25. }
  26.  
  27. $sql = "INSERT INTO dados (Nome, Idade, Genero)
  28. VALUES ('$Nome', '$Idade', '$Genero')";
  29.  
  30. if (mysqli_query($conn, $sql)) {
  31. echo "New record created successfully";
  32. } else {
  33. echo "Error: " . $sql . "<br>" . mysqli_error($conn);
  34. }
  35.  
  36. mysqli_close($conn);
  37.  
  38. ?>
Add Comment
Please, Sign In to add comment