In my web application there is a table user can see the data(id,date phone number etc.). But i want to add add search facility there(Search by ID/phone no). My code is not working and saying "Could not execute query: SELECT * FROM 'xxx' WHERE 'xxx' LIKE Connect.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 ''xxx' WHERE 'xxx' LIKE Connect' at line 1"
This is my code
----------------------------[php]
<form target="mainFra me" action="search. php" method="post">
Search By
<select name="col">
<option value="Author"> District</option>
<option value="xxx">xxx </option>
</select>
<input name="search" type="text">
<input type="submit" name="submit" value="search">
</form>
<?php
include 'dbconnect.php' ;
$db=mysql_selec t_db(mmm,$dbh) or die("Could not select database");
if($_POST['col']=="yyy"){
$q="SELECT * FROM 'xxx' WHERE 'xxx' LIKE $_POST[search]" ;
}
if($_POST['col']=="xxx"){
$q="SELECT * FROM 'xxx' WHERE 'xxx' LIKE $_POST[search]" ;}
$result=mysql_q uery($q) or die ("Could not execute query: $q.".mysql_erro r());
while($row=mysq l_fetch_array($ result)){
$ID=$row["ID"];
$xxx=$row["xxx"];
$PhoneNo=$row["PhoneNo"];
$District=$row["District"];
$date=$row["date"];
$vDescription=$ row["Descriptio n"];?>
<tr class="row">
</td>
</tr>
<?php }?>[/php]
Please enclose any code within the proper code tags. See the Posting Guidelines on how to do that.
MODERATOR
This is my code
----------------------------[php]
<form target="mainFra me" action="search. php" method="post">
Search By
<select name="col">
<option value="Author"> District</option>
<option value="xxx">xxx </option>
</select>
<input name="search" type="text">
<input type="submit" name="submit" value="search">
</form>
<?php
include 'dbconnect.php' ;
$db=mysql_selec t_db(mmm,$dbh) or die("Could not select database");
if($_POST['col']=="yyy"){
$q="SELECT * FROM 'xxx' WHERE 'xxx' LIKE $_POST[search]" ;
}
if($_POST['col']=="xxx"){
$q="SELECT * FROM 'xxx' WHERE 'xxx' LIKE $_POST[search]" ;}
$result=mysql_q uery($q) or die ("Could not execute query: $q.".mysql_erro r());
while($row=mysq l_fetch_array($ result)){
$ID=$row["ID"];
$xxx=$row["xxx"];
$PhoneNo=$row["PhoneNo"];
$District=$row["District"];
$date=$row["date"];
$vDescription=$ row["Descriptio n"];?>
<tr class="row">
</td>
</tr>
<?php }?>[/php]
Please enclose any code within the proper code tags. See the Posting Guidelines on how to do that.
MODERATOR
Comment