Skip to content

Instantly share code, notes, and snippets.

@juddlyon
Created May 22, 2016 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juddlyon/30a1fce29fca333d9b5ff853688088dc to your computer and use it in GitHub Desktop.
Save juddlyon/30a1fce29fca333d9b5ff853688088dc to your computer and use it in GitHub Desktop.
GA Programming for Non-programmers POST Form Handler
<?php
$servername = "example.org";
$database = "your_db_name";
$username = "your_username";
$password = "your_password";
try {
$conn = new PDO("mysql:host=$servername;dbname=$database", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
/* INSERT */
$sql = "INSERT INTO users (first_name, last_name, email, bio)
VALUES (:first_name, :last_name, :email, :bio)";
$prep = $conn->prepare($sql);
$prep->execute(array(
':first_name' => $_POST['first_name'],
':last_name' => $_POST['last_name'],
':email' => $_POST['email'],
':bio' => $_POST['bio']
));
echo "New record created successfully";
} catch(PDOException $error) {
echo "Connection failed: " . $error->getMessage();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment