Click here to Skip to main content
15,902,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello guys,

i need some help, im trying to filter my table using php but it gives me this error "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 '= 'hes'' at line 1" below is my code.

HTML
<form name="search_form" method="POST" action="index.php">
				
								
<select name="search_pad">
<option value="hes">HES</option>
<option value="WFBS">WFBS</option>
</select>
								
<input type="submit" name="search" value="test"/>
</form>


PHP
<?php
include ("include/db_connection.php");
										
$sql = "SELECT * FROM tbl_masterlist";
										
										if(isset($_POST['search'])){
										
$search_term = mysql_real_escape_string($_POST['search_pad']);
										
$sql .= "where p0_product = '{$search_term}' ";
										
}
										
$query = mysql_query($sql) or die(mysql_error());
?>	


Thanks in advance
Makubex
Posted
Updated 4-Aug-13 7:30am
v3

in your verification you are using $_POST['search']

but in your usage you are using $_POST['search_pad']

that is not the problem.
The main problem is a classic rookie mistake :)



PHP
$sql = "SELECT * FROM tbl_masterlist";
$sql .= "where p0_product = '{$search_term}' ";
//this generate 
$sql="SELECT * FROM tbl_masterlistwhere p0_product = 'search term'"; // so what you need is a space between your table name and where keyword 
 
Share this answer
 
Comments
athan_makubex 5-Aug-13 10:58am    
Hi Mohibur, itried your solution and i put a space between tbl_masterlist<space>" and it working now. thank you for your suggestion it helps me a lot!
Mohibur Rashid 5-Aug-13 20:47pm    
you are welcome
try this
pls check this
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900