Skip to content

Instantly share code, notes, and snippets.

@sudarshanReddykurri
Created September 1, 2016 07:05
Show Gist options
  • Save sudarshanReddykurri/75151e6ddca2e90d3e6063bad7b9ba5a to your computer and use it in GitHub Desktop.
Save sudarshanReddykurri/75151e6ddca2e90d3e6063bad7b9ba5a to your computer and use it in GitHub Desktop.
Inserting into mysql database using PDO Prepare Statement
<?php
$database='database';
$email=$_POST['subscribe'];
$host='localhost';
$user='root';
$password='root';
$result=0;
try {
$dbo = new PDO('mysql:host='.$host.';dbname='.$database, $user, $password);
$dbo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = $dbo->prepare("INSERT INTO subscribers (subscribe) VALUES (:useremail)");
$sql->bindParam(':useremail', $email, PDO::PARAM_STR, 50);
$result=$sql->execute();
} catch (PDOException $e) {
print "Error " . $e->getMessage() . "<br/>";
die();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment