Jump to content

Search Code Issue


pziggy

Recommended Posts

I am having an issue with this search code. Could someone have a look and point out the obvious. I am over looking something.

 

The code will not produce errors it will not do anything. LOL I knida wish it would error at least i could see something.. MYSQL version is 4.1.22-standard.

 

I am trying to make this query work on a single page without the search text being sent thru the url. I have read up on this and have come to a wall. Not sure whats next..

 

<HTML>
<HEAD>
<TITLE> Parts Search </TITLE>
<HEAD>
<BODY>
	<p>Search Parts</p>
	<p>
<form name="search" method="post" action="<?=$PHP_SELF?>">
  <input type="text" name="yampart" />
<input type="submit" name="search" value="Search" />
</form></p>

<?php
$search = $_POST[’yampart’];

if ($search == "")
  {
  echo "<p>Enter a Part Number</p>";
  exit;
  }

if (!isset($search))
  {
  echo "<p>We can't search for that</p>";
  exit;
  }

mysql_connect("localhost","USERNAME","PASSWORD"); 
mysql_select_db("DBNAME") or die("Unable to select database");


$query = "select * from yamaha_parts WHERE ITEM_NO ='$search'";  
  
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
$result = mysql_db_query("nmotiona_parts", $query); 

if ($result) 
{ 
echo "Here are the results:<br><br>"; 
echo "<table width=200px align=center><tr> 
<td align=center bgcolor=#00FFFF>Part Number</td> 
<td align=center bgcolor=#00FFFF>Description</td> 
<td align=center bgcolor=#00FFFF>Package Quanity</td> 
<td align=center bgcolor=#00FFFF>Retail Price</td> 
</tr>"; 

while ($r = mysql_fetch_array($result)) { 
$part = $r["ITEM_NO"]; 
$desc = $r["DESC"]; 
$qty = $r["PACK_QTY"]; 
$retail = $r["SUG_RETAIL"]; 
echo "<tr> 
<td>$part</td> 
<td>$desc</td> 
<td>$qty</td> 
<td  bgcolor=\"#ffffa0\">$retail</td> 
</tr>"; 
} 
echo "</table>"; 
} 
else { echo "Sorry that Part number is not in our database"; }

?>
</BODY>
</HTML>



 

Thanks for sharing your time..

 

Pziggy

Link to comment
Share on other sites

$query = "select * from yamaha_parts WHERE ITEM_NO ='$search'";  // is this INT
  
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
$result = mysql_db_query("nmotiona_parts", $query); // redundant i guess

 

remove the  ' ' if that is an INT ITEM_NO ='$search'" should be ITEM_NO =$search"

 

Link to comment
Share on other sites

$numresults=mysql_query($query); <--- this i shouldn't need It will be one item returned..

$numrows=mysql_num_rows($numresults); <--this also axed

$result = mysql_db_query("nmotiona_parts", $query); <this was a mistake that was not deleted in the pasting of the example. So with those changes it looks ok?

 

I wanna thank you for your time. I will give it a try.

Link to comment
Share on other sites

code edited to this.. still does nothing. Maybe There is an easier way. this should just be a simple search for an exact match. I have a tendency to complicate such things..

 

 

<HTML>
<HEAD>
<TITLE> Parts Search </TITLE>
<HEAD>
<BODY>
	<p>Search Parts</p>
	<p>
<form name="search" method="post" action="<?=$PHP_SELF?>">
  <input type="text" name="yampart" />
<input type="submit" name="search" value="Search" />
</form></p>

<?php
$search = $_POST[’yampart’];

if ($search == "")
  {
  echo "<p>Enter a Part Number</p>";
  exit;
  }

if (!isset($search))
  {
  echo "<p>We can't search for that</p>";
  exit;
  }

mysql_connect("localhost","USERNAME","PASSWORD"); 
mysql_select_db("DBNAME") or die("Unable to select database");


$query = "select * from yamaha_parts WHERE ITEM_NO =$search";  
  


if ($result) 
{ 
echo "Here are the results:<br><br>"; 
echo "<table width=200px align=center><tr> 
<td align=center bgcolor=#00FFFF>Part Number</td> 
<td align=center bgcolor=#00FFFF>Description</td> 
<td align=center bgcolor=#00FFFF>Package Quanity</td> 
<td align=center bgcolor=#00FFFF>Retail Price</td> 
</tr>"; 

while ($r = mysql_fetch_array($result)) { 
$part = $r["ITEM_NO"]; 
$desc = $r["DESC"]; 
$qty = $r["PACK_QTY"]; 
$retail = $r["SUG_RETAIL"]; 
echo "<tr> 
<td>$part</td> 
<td>$desc</td> 
<td>$qty</td> 
<td  bgcolor=\"#ffffa0\">$retail</td> 
</tr>"; 
} 
echo "</table>"; 
} 
else { echo "Sorry that Part number is not in our database"; }

?>
</BODY>
</HTML>

 

What I am trying to do is pull ITEM_NO, DESC, PACK_QTY, And SUG_RETAIL from a table named yamaha_parts when a search for the ITEM_NO exactly matches. and display them. all on the same page (meaning the search and code will be on the same page). Maybe I do not need all this code. from what i have been learning there are alot of way to code this. Maybe some are better than others. I would like it to learn the correct way so I can do future queries without coding errors..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.