0

I am trying to create a very simple and basic search script.

Here is what I have done so far:

include('config.php');

$search_token =$_POST['search_token'];

$search_query = mysqli_query($conn, "SELECT Forname FROM idea WHERE post_des LIKE '%$search_token%'");

while($row = mysqli_fetch_array($search_query))
  {

  $idea_body = $row['post_des'];

  echo $idea_body;
}

But when I execute this, I am having the following Warning:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in F:\Server\xampp\htdocs\p\c3\search.php on line 34

Any help for this situation?

3
  • what is the table structure? Commented Dec 18, 2013 at 6:59
  • echo your query and make sure it is executing properly. Commented Dec 18, 2013 at 7:00
  • Be alarm about $search_token = $_POST['search_token']. You could SQL-inject yourself :) Commented Dec 18, 2013 at 7:11

2 Answers 2

1

You probably have a problem in your query, try:

$search_query = mysqli_query($conn, "SELECT Forname FROM idea WHERE post_des LIKE '%$search_token%'") or die(mysqli_error($conn));

To debug your query.

Sign up to request clarification or add additional context in comments.

2 Comments

i think this is probably more suitable for comment.
oh my!! This fixed that. Thanks a lot!
0

Your query is failing and returning a false value.

put this after your mysqli_query() to see whats going on.

if (!$search_query) {
    printf("Error: %s\n", mysqli_error($con));
    exit();
}

for more information.

http://www.php.net/manual/en/mysqli.error.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.