1

the warning message above is shown when the site is searched. It is a simple search feature which displays all the records, matching the search word with a field in the table. The code is as below.

if(isset($_POST['submit'])){ $clean_search_word = mysqli_real_escape_string($con,$_POST['search_word']); $sql = "SELECT * FROM webdir_user where user_category like '%$clean_search_word%'"; $record = mysqli_query($con,$sql); if(!$record){ die('Error in SQL:'.mysql_error()); } else{ while($result = mysqli_fetch_array($record,$con)){ } } } 

I have found answers to kind of same issues as mine, but in most of the cases the warning message was caused by something else so I couldn't find any help with figuring out what caused the problem in my case. Any help or advise as to how to resolve. Thank you.

1
  • this question have been answered many times, please browse through SO, before asking any question Commented Mar 2, 2017 at 12:29

2 Answers 2

3

Remove the $con from your mysqli_fetch_array and it should work. There is only 1 string allowed in this 'function'. The other one ($con) is optional and has to be an integer. Like MYSQLI_ASSOC

if(isset($_POST['submit'])){ $clean_search_word = mysqli_real_escape_string($con,$_POST['search_word']); $sql = "SELECT * FROM webdir_user where user_category like '%$clean_search_word%'"; $record = mysqli_query($con,$sql); if(!$record){ die('Error in SQL:'.mysql_error()); } else{ while($result = mysqli_fetch_array($record)){ } } } 
Sign up to request clarification or add additional context in comments.

3 Comments

@Gobbin..Thanks a lot. I just realized the mistake before I looked at your answer. I shall accept your answer in a few minutes. Thanks for your time
Also, you are using mysqli but in the if statement - if you cant execute the query - you are giving a mysql_error. That should be a mysqli_error(); :)
Answer accepted as it is the solution to my problem.
2

mysqli_fetch_array takes one parameter (the $result) another optional one which is INTEGER (int $resulttype = MYSQLI_BOTH )

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.