html - PHP Search from Database -
this question has answer here:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title>test query</title> </head> <body> <form action="" method="get"> search: <input type="text" name="query" /> <br /> please enter last name <input type="submit" value="submit" /> </form> <?php $db_hostname = 'localhost'; $db_username = 'zvrub'; $db_password = 'zvrub'; $db_database = 'dbtest'; $con = mysql_connect($db_hostname,$db_username,$db_password,$db_database); if (!$con) { die('could not connect: ' . mysql_error()); } mysql_select_db($db_database, $con); $query = $_get['query']; $min_length = 1; if(strlen($query) >= $min_length){ $query = htmlspecialchars($query); $query = mysql_real_escape_string($query); $raw_results = mysql_query("select * 'hr data' (`last_name` '%".$query."%') or (`last_name` '%".$query."%')") or die(mysql_error()); if(mysql_num_rows($raw_results) > 0){ while($results = mysql_fetch_array($raw_results)){ echo "<p><h3>".$results['title']."</h3>".$results['text']."</p>"; } } else{ } } else{ echo "minimum length ".$min_length; } ?> </body> </html>
i have code gives me error of: have error in sql syntax; check manual corresponds mysql server version right syntax use near ''hr data' (last_name
'%bryant%') or (last_name
'' @ line 1
try using backticks (`) instead of single quotes (') delimit table name
"select * `hr data`
Comments
Post a Comment