Advertisement
Guest User

va

a guest
Jun 25th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.79 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL);
  3. try {
  4.     $pdo = new PDO('mysql:host=127.0.0.1;dbname=to_do_list', 'root', '');
  5.  
  6. } catch (PDOException $e){
  7. echo $e->getMessage ();
  8.     die('Could not connected');
  9. }
  10. $pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
  11.  
  12.  
  13. $sql = "INSERT INTO tasks(title, due_date, description) VALUES (
  14.            :title
  15.            :due_date
  16.            :description)";
  17.  
  18. $stmt = $pdo->prepare($sql);
  19. if (!$stmt) {
  20.     echo "\nPDO::errorInfo():\n";
  21.     print_r($pdo->errorInfo());
  22. }
  23. $stmt->bindParam(':title', $_POST['title'], PDO::PARAM_STR);
  24. $stmt->bindParam(':due_date', $_POST['due_date'], PDO::PARAM_STR);
  25. $stmt->bindParam(':description', $_POST['description'], PDO::PARAM_STR);
  26. $stmt->execute();
  27.  
  28.  
  29. $result = $stmt->execute();
  30. var_dump($result)
  31. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement