Skip to content

Instantly share code, notes, and snippets.

@Faizanq
Created January 27, 2019 07:07
Show Gist options
  • Save Faizanq/1146f9b56621578aec12a597101e3196 to your computer and use it in GitHub Desktop.
Save Faizanq/1146f9b56621578aec12a597101e3196 to your computer and use it in GitHub Desktop.
require "../config.php";
require "../common.php";
try {
$connection = new PDO($dsn, $username, $password, $options);
$new_user = array(
"firstname" => $_POST['firstname'],
"lastname" => $_POST['lastname'],
"email" => $_POST['email'],
"age" => $_POST['age'],
"location" => $_POST['location']
);
$sql = sprintf(
"INSERT INTO %s (%s) values (%s)",
"users",
implode(", ", array_keys($new_user)),
":" . implode(", :", array_keys($new_user))
);
$statement = $connection->prepare($sql);
$statement->execute($new_user);
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment