Advertisement
Guest User

Untitled

a guest
May 30th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: aleksejjj
  5. * Date: 5/31/2016
  6. * Time: 3:14 AM
  7. */
  8.  
  9. // Connect Data
  10. $db_host = 'localhost';
  11. $db_name = 'test';
  12. $db_user = 'louiseda_admin';
  13. $db_pass = 'Password1';
  14.  
  15. // Important!!! Comment 'print' line in production using!!!
  16. try
  17. {
  18. $dbh = new PDO('mysql:host='. $db_host .';dbname=' . $db_name, $db_user, $db_pass);
  19. }
  20. catch (PDOException $e)
  21. {
  22. print "Error!: " . $e->getMessage() . "<br/>";
  23. die();
  24. }
  25.  
  26. // If fields empty - die
  27. if (empty($_POST['name']) || empty($_POST['email']) || empty($_POST['attend']) || empty($_POST['note']))
  28. {
  29. die();
  30. }
  31. $sth = $dbh->prepare('INSERT INTO users (name, email, attend, note) VALUES (:name, :email, :$attend, :note)');
  32. $sth->bindParam('name', $_POST['name'], PDO::PARAM_STR);
  33. $sth->bindParam('email', $_POST['email'], PDO::PARAM_STR);
  34. $sth->bindParam('attend', $_POST['attend'], PDO::PARAM_STR);
  35. $sth->bindParam('note', $_POST['note'], PDO::PARAM_STR);
  36.  
  37. $sth->execute();
  38.  
  39. return 'ok';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement