Advertisement
Guest User

Untitled

a guest
Mar 28th, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. <?php
  2. $nombre = filter_input(INPUT_POST, 'nombre');
  3. $apellido = filter_input(INPUT_POST, 'apellido');
  4. $pais = filter_input(INPUT_POST, 'pais');
  5. $asunto = filter_input(INPUT_POST, 'asunto');
  6.  
  7. if (!empty($nombre) || !empty($apellido) || !empty($pais) || !empty($asunto)){
  8. $host = "localhost";
  9. $dbusername = "root";
  10. $dbpassword = "";
  11. $dbname = "webfinal";
  12. $table = "contacto";
  13.  
  14. // Create connection
  15. $conn = new mysqli ($host, $dbusername, $dbpassword, $dbname);
  16.  
  17. if (mysqli_connect_error()){
  18. die('Connect Error ('. mysqli_connect_errno() .') '. mysqli_connect_error());
  19. } else{
  20. $sql = "INSERT INTO $table (nombre, apellido, pais, asunto) values ('$nombre', '$apellido', '$pais', '$asunto')";
  21. if ($conn->query($sql)){
  22. redirect("http://localhost/webfinal/pages/contact.php");
  23. } else{
  24. echo "Error: ". $sql ."". $conn->error;
  25. }
  26. $conn->close();
  27. }
  28. }
  29.  
  30. function redirect($url) {
  31. ob_start();
  32. header('Location: '.$url);
  33. ob_end_flush();
  34. die();
  35. }
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement