Advertisement
Guest User

Untitled

a guest
Apr 27th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. // always initialize a variable before use!
  2. $conditions = array();
  3. $parameters = array();
  4.  
  5. if (!empty($_POST['myparam'])) {
  6. $q1 = trim($_POST['myparam']);
  7. $q_myvar = $q1;
  8. $conditions[] = 'mycol = ?';
  9. $parameters[] = $q_myvar;
  10. }
  11.  
  12. $q = "SELECT * FROM mytable";
  13.  
  14. if ($conditions)
  15. {
  16. $q .= " WHERE ".implode(" AND ", $conditions);
  17. }
  18.  
  19. $stmt = $conn->prepare($q);
  20. $stmt->execute($parameters);
  21. $data = $stmt->fetchAll();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement