Skip to content

Instantly share code, notes, and snippets.

@guilhermeof
Last active June 6, 2016 13:56
Show Gist options
  • Save guilhermeof/fbaf988a0c3f5d0ff93da2660ae8a04a to your computer and use it in GitHub Desktop.
Save guilhermeof/fbaf988a0c3f5d0ff93da2660ae8a04a to your computer and use it in GitHub Desktop.
$name = $_POST["name"];
$email = $_POST["email"];
$user = "root";
$pass = "root";
$dsn = "mysql:host=localhost;dbname=formacao_php";
$pdo = new PDO($dsn, $user, $pass);
$sql = "INSERT INTO usuarios (name, email) VALUES (:nome,:email)";
$insert = $pdo->prepare($sql);
$insert->bindParam(":nome", $name, PDO::PARAM_STR);
$insert->bindParam(":email", $email, PDO::PARAM_STR);
if ($insert->execute()){
print $pdo->lastInsertId();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment