Advertisement
Guest User

Untitled

a guest
May 31st, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. <?php
  2. $host = "localhost";
  3. $dbname = "scotchbox";
  4. $user = "root";
  5. $pass = "root";
  6.  
  7. try {
  8. // Abre a conexão com o DB
  9. $conn = new PDO("mysql:host = $host; dbname = $dbname", $user, $pass);
  10. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  11. // Faz a operação de INSERT no DB
  12. $stmt = $conn->prepare("INSERT INTO usuarios (nome, idade) VALUES (:nome, :idade)");
  13. $stmt = bindParam(":nome", $_POST["nome"]);
  14. $stmt = bindParam(":idade", $_POST["idade"]);
  15. $stmt->execute();
  16.  
  17. echo "Valores inseridos com sucesso!";
  18. } catch {
  19. echo "ERRO: " . $e->getMessage();
  20. }
  21. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement