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
https://forums.phpfreaks.com/topic/64172-search-code-issue/
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
https://forums.phpfreaks.com/topic/64172-search-code-issue/#findComment-319840
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
https://forums.phpfreaks.com/topic/64172-search-code-issue/#findComment-319864
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
https://forums.phpfreaks.com/topic/64172-search-code-issue/#findComment-319872
Share on other sites

 

Try to look at this forumhttp://www.keithjbrown.co.uk/vworks/php/php_p2.php

 

If you textbox is yampart,then in your query ...

$query = "select * from yamaha_parts WHERE ITEM_NO ='{$_POST['yampart']}')";

 

If you go through the ulr that i gave surely you will be able  to overcome your problem...It helps me...

 

Good luck...

 

 

Link to comment
https://forums.phpfreaks.com/topic/64172-search-code-issue/#findComment-324329
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.