Advertisement
Guest User

Untitled

a guest
May 30th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 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. die('WTF????????????? Cache?????????????????');
  10.  
  11. // Connect Data
  12. $db_host = 'localhost';
  13. $db_name = 'louiseda_rsvp';
  14. $db_user = 'louiseda_admin';
  15. $db_pass = 'Password1';
  16.  
  17. // Important!!! Comment 'print' line in production using!!!
  18. try
  19. {
  20. $dbh = new PDO('mysql:host='. $db_host .';dbname=' . $db_name, $db_user, $db_pass);
  21. }
  22. catch (PDOException $e)
  23. {
  24. print "Error!: " . $e->getMessage() . "<br/>";
  25. die();
  26. }
  27.  
  28. echo '>>>';
  29. echo $_POST['name'];
  30. echo '<<<';
  31.  
  32. // If fields empty - die
  33. if (empty($_POST['name']) || empty($_POST['email']) || empty($_POST['attend']) || empty($_POST['note']))
  34. {
  35. echo $_POST['name'];
  36. echo $_POST['email'];
  37. echo $_POST['attend'];
  38. echo $_POST['note'];
  39. die('Error!');
  40. }
  41. print_r($_POST);
  42.  
  43. $sth = $dbh->prepare('INSERT INTO users (name, email, attend, note) VALUES (:name, :email, :$attend, :note)');
  44. $sth->bindParam('name', $_POST['name'], PDO::PARAM_STR);
  45. $sth->bindParam('email', $_POST['email'], PDO::PARAM_STR);
  46. $sth->bindParam('attend', $_POST['attend'], PDO::PARAM_STR);
  47. $sth->bindParam('note', $_POST['note'], PDO::PARAM_STR);
  48.  
  49. $sth->execute();
  50.  
  51. if (!$sth) {
  52. echo "\nPDO::errorInfo():\n";
  53. print_r($dbh->errorInfo());
  54. }
  55.  
  56. return 'ok';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement