Guest User

Untitled

a guest
Mar 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. <?php
  2.  
  3. include('../config.php');
  4.  
  5. $query = "
  6. SELECT
  7. id,
  8. pseudo
  9. FROM users
  10. ";
  11.  
  12. try
  13. {
  14. // These two statements run the query against your database table.
  15. $stmt = $db->prepare($query);
  16. $stmt->execute();
  17. }
  18. catch(PDOException $ex)
  19. {
  20. // Note: On a production website, you should not output $ex->getMessage().
  21. // It may provide an attacker with helpful information about your code.
  22. die("Failed to run query: " . $ex->getMessage());
  23. }
  24.  
  25. // Finally, we can retrieve all of the found rows into an array using fetchAll
  26. $info = $stmt->fetchAll();
  27. $id = $array[0]['id'];
  28. print_r($info);
  29.  
  30.  
  31.  
  32. switch ($_REQUEST['action']) {
  33. case 'sendMessage':
  34. $query = $db->prepare("INSERT INTO messages SET id_user = ?, content=?");
  35. $query->execute([$id,$_REQUEST['message']]);
  36. break;
  37. }
  38. ?>
Add Comment
Please, Sign In to add comment