Jump to content

[SOLVED] search form returns no results


aebstract

Recommended Posts

Hi,

I had a search form working fine, searching for part numbers in a database. I just added a drop down menu to give the user an option between searching for part numbers or description, though now I am returning no results at all for either option. I don't think the variable is being passed in to the query correctly:

 

form

$content .= "
<form action=\"/find/\" method=\"post\" name=\"searchparts\">
<table>
<tr><td>
Search for:
</td></tr>
<tr><td>
<select name=\"searchfor\">
<option value=\"PN\">Part Number</option>
<option value=\"`DESC`\">Description</option>
</select>
<input type=\"text\" maxlength=\"20\" name=\"partsearch\" value=\"$_POST[partsearch]\" size=\"20\" />
<input type=\"text\" name=\"bogusField\" style=\"display: none;\" />

</td></tr>
<tr><td>
<input type=\"submit\" name=\"submit\" value=\"Search\" />
</td></tr>
</table>
</form>
";

 

 

 

query

if(isset($_POST['submit'])) {

      if (empty ($_POST['partsearch'])) {
      } else {

$partsearch = $_POST['partsearch'];
$searchfor = $_POST['searchfor'];

    $color1 = "#dddddd";
    $color2 = "#c0c0c0";
    $row_count = 0;



$content .= "<form action=\"/cart/\" method=\"post\">
<table width=732 cellpadding=3><tr bgcolor=#8d8d8d cellspacing=6><td width=10 align=center class=tclassd>MCHN</td><td width=100 class=tclassd>Part Number</td><td width=475>Description</td><td width=50>Price</td><td>QTY</td></tr>";


$result2 = mysql_query("SELECT * FROM parts WHERE '$searchfor' LIKE '%$partsearch%'") or DIE(mysql_error());
while($r2=mysql_fetch_array($result2))
{
$pid=$r2["id"];
$loc=$r2["LOC"];
$pn=$r2["PN"];
$desc=$r2["DESC"];
$price=$r2["PRICE"];
$sub=$r2["SUB"];
$mchn=$r2["MCHN"];





etc etc etc, just displays the information, didn't change so I know it all works correctly down here.

Link to comment
https://forums.phpfreaks.com/topic/101562-solved-search-form-returns-no-results/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.