Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: aleksejjj
- * Date: 5/31/2016
- * Time: 3:14 AM
- */
- // Connect Data
- $db_host = 'localhost';
- $db_name = 'test';
- $db_user = 'louiseda_admin';
- $db_pass = 'Password1';
- // Important!!! Comment 'print' line in production using!!!
- try
- {
- $dbh = new PDO('mysql:host='. $db_host .';dbname=' . $db_name, $db_user, $db_pass);
- }
- catch (PDOException $e)
- {
- print "Error!: " . $e->getMessage() . "<br/>";
- die();
- }
- // If fields empty - die
- if (empty($_POST['name']) || empty($_POST['email']) || empty($_POST['attend']) || empty($_POST['note']))
- {
- die();
- }
- $sth = $dbh->prepare('INSERT INTO users (name, email, attend, note) VALUES (:name, :email, :$attend, :note)');
- $sth->bindParam('name', $_POST['name'], PDO::PARAM_STR);
- $sth->bindParam('email', $_POST['email'], PDO::PARAM_STR);
- $sth->bindParam('attend', $_POST['attend'], PDO::PARAM_STR);
- $sth->bindParam('note', $_POST['note'], PDO::PARAM_STR);
- $sth->execute();
- return 'ok';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement