Guest User

Untitled

a guest
Apr 26th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. <?php
  2. class Main{
  3. //fetching posts from database
  4. public function posts(){
  5. global $conn;
  6. $query = $conn->prepare("SELECT * FROM `posts`,`users` WHERE userId = user_id_p ORDER BY `post_id` DESC");
  7. $query->execute();
  8. return $query->fetchAll();
  9. }
  10. //add new post if user post
  11. public function add_post($user_id,$status,$file_parh){
  12. global $conn;
  13. if(empty($file_parh)){
  14. $file_parh = 'NULL';
  15. }
  16. $query = $conn->prepare('INSERT INTO `posts` (`post_id`, `user_id_p`, `status`, `status_image`, `status_time`) VALUES (NULL, ?, ?,?, CURRENT_TIMESTAMP)');
  17. $query->bindValue(1,$user_id);
  18. $query->bindValue(2,$status);
  19. $query->bindValue(3,$file_parh);
  20. $query->execute();
  21. header('Location: home.php?id='.$_POST['email']);
  22. }
  23. //fetch user data by user id
  24. public function user_data($user_id){
  25. global $conn;
  26. $query = $conn->prepare('SELECT * FROM users WHERE userId = ?');
  27.  
  28. //Line 28 below
  29.  
  30. $query->bindvalue(1,$user_id);
  31. $query->execute();
  32.  
  33. return $query->fetch();
  34. }
  35. ?>
Add Comment
Please, Sign In to add comment