pziggy Posted August 9, 2007 Share Posted August 9, 2007 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 Quote Link to comment Share on other sites More sharing options...
teng84 Posted August 10, 2007 Share Posted August 10, 2007 $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" Quote Link to comment Share on other sites More sharing options...
pziggy Posted August 10, 2007 Author Share Posted August 10, 2007 $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. Quote Link to comment Share on other sites More sharing options...
pziggy Posted August 10, 2007 Author Share Posted August 10, 2007 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.. Quote Link to comment Share on other sites More sharing options...
Thivya Posted August 15, 2007 Share Posted August 15, 2007 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... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.