Guest User

Untitled

a guest
Oct 22nd, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. **My goal in this code is to create apply later section for the user and I created an hidden button to get the id of the exact post, i am getting the id but when i bind and execute i am having this warning, i have checked several other peoples question similar to mine but they do not seem to solve my exact problem **
  2.  
  3. if(isset($_POST['submit'])){
  4. $id = $_POST['applylater_id'];// I got this from a button the user is to click
  5. // INSERT INTO MYSQL
  6. $this->query('INSERT INTO apply_later(id, title, body, link, user_id, user_name) SELECT id, title, body, link, user_id, user_name FROM shares WHERE id = :id');
  7. $this->bind(':title', 'title');
  8. $this->bind(':body', 'body');
  9. $this->bind(':link', 'link');
  10. $this->bind(':user_id', 1);
  11. $this->bind(':user_name', 'user_name');
  12. $this->bind(':id', $id);
  13. $this->execute();
  14.  
  15. //Verify
  16. if($this->lastInsertId()){
  17. //Redireect
  18. Messages::setMsg('Successfully Added to your apply Later section', 'successMsg');
  19. header( "refresh:2; url=http://localhost/phpsandbox/phptutorials/website2/shares/applylater" );
  20.  
  21. }
  22. }
  23. //
  24. $this->query('SELECT * FROM shares ORDER by id desc ');
  25. $rows = $this->resultSet();
  26. return $rows;
  27.  
  28. public function query($query){
  29. $this->stmt = $this->dbh->prepare($query);
  30. }
  31.  
  32.  
  33. public function bind ($param, $value, $type =null) {
  34. if(is_null($type)){
  35. switch(true) {
  36. case is_int($value):
  37. $type = PDO::PARAM_INT;
  38. break;
  39. case is_bool($value):
  40. $type = PDO::PARAM_BOOL;
  41. break;
  42. case is_null($value):
  43. $type = PDO::PARAM_NULL;
  44. break;
  45. default:
  46. $type = PDO::PARAM_STR;
  47. }
  48.  
  49. }
  50. $this->stmt->bindValue($param, $value, $type);
  51. }
  52.  
  53. public function execute(){
  54. return $this->stmt->execute();
  55. }
  56.  
  57. <?php foreach ($viewmodel as $item) : ?>
  58. <div class="well">
  59. <div class="text-center">
  60. <img src="http://localhost/phpsandbox/phptutorials/website2/assets/image/job.png" class="img-circle" alt="Cinque Terre" width="50" height="50">
  61.  
  62. <h3> <?php echo $item['title']; ?></h3>
  63. <small> Username: <?php echo $item['user_name']; ?></small>
  64. <br />
  65. <small><?php echo $item['create_date']; ?></small>
  66. </div>
  67. <hr />
  68. <p><?php echo $item['body']; ?></p>
  69. <br />
  70. <div class="text-center">
  71. <a href="<?php echo $item['link']; ?>" target="_blank" class="btn btn-info">Apply Now</a>
  72. <br />
  73.  
  74. </div>
  75. <hr />
  76. <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>" >
  77.  
  78. <input type="hidden" name="applylater_id" value="<?php echo $item['id']; ?>">
  79. <input class="btn btn-primary" type="submit" name="submit" value="Apply Later">
  80. </form>
  81.  
  82. </div>[enter image description here][1]
Add Comment
Please, Sign In to add comment