Guest User

Untitled

a guest
Jan 23rd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. $sql = 'SELECT * FROM items WHERE (i_name LIKE ='%$query%') OR (i_code LIKE '%$query%')';
  2.  
  3. Warning: mysqli_stmt_bind_param(): Number of variables doesn't match number of parameters in prepared statement in
  4.  
  5. if(isset($_REQUEST['term'])){
  6. // Prepare a select statement
  7. $sql = 'SELECT * FROM items WHERE (i_name LIKE ?) OR (i_code LIKE ?)';
  8.  
  9. if($stmt = mysqli_prepare($ds, $sql)){
  10. // Bind variables to the prepared statement as parameters
  11. mysqli_stmt_bind_param($stmt, "s", $param_term);
  12.  
  13. // Set parameters
  14. $param_term = $_REQUEST['term'] . '%';
  15.  
  16. // Attempt to execute the prepared statement
  17. if(mysqli_stmt_execute($stmt)){
  18. $result = mysqli_stmt_get_result($stmt);
  19.  
  20. // Check number of rows in the result set
  21. if(mysqli_num_rows($result) > 0){
  22. // Fetch result rows as an associative array
  23. echo '<table class="table table-striped"><tbody><tr>';
  24. while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
  25.  
  26. echo '<td width="70%">' . $row["i_name"] . '</td><td width="30%"><a href="edit-cat.php?cat='.$row['iid'].'"><i class="fa fa-pencil" aria-hidden="true"></i> Edit</a></td>';
  27. }
  28. echo '</tr></tbody></table>';
  29. } else{
  30. echo "<p>No matches found</p>";
  31. }
  32. } else{
  33. echo "ERROR: Could not able to execute $sql. " . mysqli_error($ds);
  34. }
  35. }
  36.  
  37. // Close statement
  38. mysqli_stmt_close($stmt);
  39. }
  40.  
  41. // close connection
  42. mysqli_close($ds);
  43. ?>
  44.  
  45. $term = "%{$_REQUEST['term']}%";
  46. mysqli_stmt_bind_param($stmt, "ss", $term, $term);
Add Comment
Please, Sign In to add comment