I 'm going to make a simple search box, but my code is not running correctly, code here:
<?php
$db_host = 'localhost';
$db_name= 'site';
$db_table= 'tablesite';
$db_user = 'root';
$db_pass = '';
$con = mysql_connect($db_host,$db_user,$db_pass) or die("خطا در اتصال به پايگاه داده");
$selected=mysql_select_db($db_name, $con) or die("خطا در انتخاب پايگاه داده");
mysql_query("SET CHARACTER SET utf8");
$dbresult=mysql_query("SELECT * FROM $db_table WHERE name LIKE '%".$_POST['search']."%' OR family LIKE '%".$_POST['search']."%'",$con);
?>
<form name="form1" dir="rtl" method="post" action="">
<label for="search"> search </label>
<input name="search" type="text" size="40" maxlength="50">
<input type="submit" name="submit" value="search"/>
also my table is like this:
CREATE TABLE tablesite (
id_user INT NOT NULL AUTO_INCREMENT ,
name VARCHAR( 128 ) NOT NULL ,
family VARCHAR( 128 ) NOT NULL ,
email VARCHAR( 64 ) NOT NULL ,
phone_number VARCHAR( 16 ) NOT NULL ,
job VARCHAR( 255 ) NOT NULL ,
username VARCHAR( 16 ) NOT NULL ,
password VARCHAR( 32 ) NOT NULL ,
confirmcode VARCHAR(32) ,
PRIMARY KEY ( id_user )
)
the error is in this line:
$dbresult=mysql_query("SELECT * FROM $db_table WHERE name LIKE '%".$_POST['search']."%' OR family LIKE '%".$_POST['search']."%'",$con);
the form fetch database and then looks for match cases if there is a same record. what I want is, it should search correctly and also show the message if there is not match cases, thanks...
note: خطا در اتصال به پایگاه داده means cant connect to db...
` at the top of the script, those aren't required. Then do `var_dump($dbresult)` after the query – Paul Stanley Oct 18 '15 at 18:09