Reputation: 23
when i start searching a record from db i got an issue when apostrophes present in word for that i used addslashes,mysql_real_escape_strin but not worked for that
<?php
include("lib/dbconn.php");
$list_query_main1="select * from table where name like '%".mysql_real_escape_string($_REQUEST['keyword'])."%'";
$list=mysql_query($list_query_main1);
echo mysql_num_rows($list);
?>
Zero results found but name present in DB give me solution.
Upvotes: 1
Views: 185
Reputation: 774
you are getting mysql error
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table' at line 1
because TABLE is reserved word. If you named your table like TABLE, you must use right mysql syntax
$list_query_main1="select * from `table` where `name` like '%".mysql_real_escape_string($_REQUEST['keyword'])."%'";
Upvotes: 1
Reputation: 551
Adding if(!$list || mysql_errno() != 0) echo mysql_error();
after line $list=mysql_query($list_query_main1);
will give you some info in case of a query failure
Otherwise myqsl_* is deprecated you should start using mysqli_* functions.
And change your last line
echo $mysql_num_rows($list);
and replace it with
echo mysql_num_rows($list);
If you want to call myqsl_num_rows() function
Upvotes: 0