Hi everyone,
What I'm trying to do is take php variables i got from user input, and
pass them as the MySQL query terms.
$query = "select * from ident where ".$searchtype1. "=".$searchterm 1."";
ERROR: Invalid query: You have an error in your SQL syntax near '=' at
line 1
I have also tried,
$query = "select * from ident where ".$searchtype1. " like
'%".$searchterm 1."%'";
ERROR: Invalid query: You have an error in your SQL syntax near 'like
'%%'' at line 1
both return similar errors as you can see. I have o idea if the problem
lies with the variable (i try echo-ing, and printing them and i get
nothing) or if it actually is with my sql syntax (i enter the first query
above in mysql from the shell without variable obviously and it returns
the results perfectly). Here is the rest of my code and any help is
greatly appreciated.
Form for getting variables:
<form action="searchr siident.php" method="post" align="center">
Choose Search Type:<br>
<select name="searchtyp e1">
<option value="NSN">NSN
<option value="NIIN">NI IN
<option value="NOMENCLA TURE">NOMENCLAT URE <option value="CAGE">CA GE
<option value="Field5"> Field5
<option value="REV">REV
<option value="EQUIP">E QUIP
<option value="RSI_P/N">RSI_P/N
<option value="WAITING_ IN">WAITING_I N <option value="NOTES">N OTES
<option value="SOS_CODE ">SOS_CODE
<option value="WORK_ORD ER">WORK_ORDE R <option value="L_QUOTE" >L_QUOTE
<option value="A_QTY">A _QTY
<option value="A_PRICE" >A_PRICE
<option value="L_WO">L_ WO
<option value="L_NOTE"> L_NOTE
</select>
<br>
Enter value to search by:<br>
<input name="searchter m1" type=text>
<br>
<input type=submit value="Search">
</form>
Relevent part of my php code (i hope):
$searchtype1 = addslashes($sea rchtype1); $searchterm1 =
addslashes($sea rchterm1);
$db = mysql_connect(" localhost", "browseuser ", "");
if (!$db)
{
echo "Error: Could not connect to database. Please try again
later."; exit;
}
}
mysql_select_db ("rsi_ident" );
$query = "select * from ident where ".$searchtype1. " like
'%".$searchterm 1."%'";
$result = mysql_query($qu ery, $db) or die("Invalid query:
".mysql_error() ); $num_results = mysql_num_rows( $result);
Thanks again
Joe
Comment