The Praetorian Posted December 31, 2006 Share Posted December 31, 2006 This script was working fine, (I think) then I went away for a while and now I can't seem to get it to work again. It won't pull out any of the search strings I enter, even the ones I know for sure are in there. Here's the code. <?php ob_start(); $dbh=mysql_connect ("localhost", "*****", "****") or die ('I cannot connect to the database because: ' . mysql_error());mysql_select_db ("author_localhost");$search_string = $_GET['s'];if ($search_string == ""){ echo "<p>There are no matches for the word you entered. Please make sure that the word is spelled correctly, and that you haven't left out any spaces or apostrophes. If your search still doesn't return a match, then we probably haven't added it yet.</p>";}else{ $result = mysql_query ("SELECT * FROM dictionary WHERE word") or die(mysql_error()); $r = mysql_fetch_array($result); if ($r['word'] != "") { echo '<h2>'.$r['word'].'</h2>'; if ($r['category'] != "") echo '<span class="blue">Category</span> <b>:</b> '.$r['category'].'<br />'; if ($r['pronounce'] != "") echo '<span class="blue">Pronunciation</span> <b>:</b> '.$r['pronounce'].'<br />'; if ($r['definition'] != "") echo ''.$r['definition'].'<br />'; if ($r['definitiontwo'] != "") echo ''.$r['definitiontwo'].'<br />'; if ($r['related'] != "") echo '<span class="blue">Related Entries</span> <b>:</b> '.$r['related'].'<br />'; echo "<br />"; echo "<title>The Shattered Realms ~ Search: $r[word]</title>"; } else { echo "<p>There are no matches for the word you entered. Please make sure that the word is spelled correctly, and that you haven't left out any spaces or apostrophes. If your search still doesn't return a match, then we probably haven't added it yet.</p>"; }}?> Link to comment Share on other sites More sharing options...
plesh Posted December 31, 2006 Share Posted December 31, 2006 This is my search facilty , hopefully it mite work for youThe form (search) <p>Search our cars </p> <form id="form1" name="form1" method="get" action="productSelectAction.php"> <div align="center"> <input name="letter" type="text" id="letter" size="15" maxlength="15" /> <input name="Submit" type="submit" id="Submit" value="Go" /> </p> </div> </form>productSelectAction.php </p> <p align="left" class="square">Product List </p><p align="left"><br /> Here you can find all the cars that we have in stock in our Beighton Warehouse, please feel free to search and if nessecary <a href="contact.php">ring us</a> for additional information regarding the used cars we sell.</p><blockquote> </blockquote><blockquote> <form action="productSelectAction.php" method="get" name="form1" id="form1"> <p> <input name="letter" type="text" id="letter" size="15" maxlength="15" /> <input type="submit" name="Submit2" value="Search" /> </p> <p> </p> </form> <p align="center"> <a href="productSelectAction.php?letter=">All</a> | <a href="productSelectAction.php?letter=A">A</a> <a href="productSelectAction.php?letter=B">B</a> <a href="productSelectAction.php?letter=C">C</a><a href="productSelectAction.php?letter=D"> D</a> <a href="productSelectAction.php?letter=E">E</a> <a href="productSelectAction.php?letter=F">F</a> <a href="productSelectAction.php?letter=G">G</a> <a href="productSelectAction.php?letter=H">H</a> <a href="productSelectAction.php?letter=I">I</a> <a href="productSelectAction.php?letter=J">J</a> <a href="productSelectAction.php?letter=K">K</a> <a href="productSelectAction.php?letter=L">L</a> <a href="productSelectAction.php?letter=M">M</a> <a href="productSelectAction.php?letter=N">N</a> <a href="productSelectAction.php?letter=O">O </a><a href="productSelectAction.php?letter=P">P</a> <a href="productSelectAction.php?letter=Q">Q</a> <a href="productSelectAction.php?letter=R">R</a> <a href="productSelectAction.php?letter=S">S</a> <a href="productSelectAction.php?letter=T">T</a> <a href="productSelectAction.php?letter=U">U</a> <a href="productSelectAction.php?letter=V">V</a> <a href="productSelectAction.php?letter=W">W</a> <a href="productSelectAction.php?letter=X">X</a> <a href="productSelectAction.php?letter=Y">Y</a> <a href="productSelectAction.php?letter=Z">Z</a> </p> <hr /></p> <p align="left"><br /> <?php include("connections.php");$initialLetter = $_GET["letter"]; // create query $query = "SELECT * FROM eshopproduct Name"; //Check initial letter if (!$initialLetter=="") { $query = $query." Where name like '$initialLetter%'"; } // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($result) > 0) { // yes // print them one after another echo "<table border=0>"; print "<tr align=center> <th>More Info</th> <th>Make</th> <th>Model</th> <th>Description</th> <th>Price</th> <th>Picture</th> </tr>"; while($row = mysql_fetch_assoc($result)) { echo "<tr align=center>"; echo "<td width=17%><a href=productsInfo.php?id=".$row[ProductId].">Info</a></td>"; echo "<td width=11%>".$row['Name']."</td>"; echo "<td width=11%>".$row['Model']."</td>"; echo "<td width=30%>".$row['Description']."</td>"; echo "<td width=18%>".$row['UnitPrice']."</td>"; echo "<td width=20%><img src=images/".$row["ImageName"]." width=100/><td>"; echo "</tr>"; } echo "</table>"; } else { // no // print status message echo "Sorry no products found!"; } // free result set memory mysql_free_result($result); // close connection mysql_close($connection); ?>All | A B C D E F G H I J K L M N O P Q R S T U V W X Y Z Link to comment Share on other sites More sharing options...
MrAdam Posted January 1, 2007 Share Posted January 1, 2007 in: $result = mysql_query ("SELECT * FROM dictionary WHERE word") or die(mysql_error()); ..."word" has no value. you need to replace it with: $result = mysql_query ("SELECT * FROM dictionary WHERE word='{$search_string}'") or die(mysql_error()); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now