Created
September 1, 2016 07:05
-
-
Save sudarshanReddykurri/75151e6ddca2e90d3e6063bad7b9ba5a to your computer and use it in GitHub Desktop.
Inserting into mysql database using PDO Prepare Statement
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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