oriental_express Posted December 30, 2009 Share Posted December 30, 2009 Hello there I'm having a bit of trouble getting my search function to work. this is my search script: http://michael-nguyen.com/greeneco/search.php <form action="<?=$PHP_SELF?>" method="post" name="search" class="style1"> <div align="center">Seach for: <input type="text" name="find" /> in <Select NAME="field"> <Option VALUE="id">ID</option> <Option VALUE="name">Name</option> <Option VALUE="pledge">Pledge</option> <Option VALUE="points">Points</option> <Option VALUE="costs">Costs</option> <Option VALUE="kwh">Kwh</option> <Option VALUE="carbon">Carbon</option> <Option VALUE="classification">Classificationn</option> <Option VALUE="energysaving">Energy Saving</option> <Option VALUE="enabled">Enabled</option> </Select> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="Search" /> </div> </form> <span class="style1"> <table border="1" width="100%"> </span> <tr><strong> <td width="35" class="style1"><span class="style5">ID</span></td> <td width="78" class="style1"><span class="style5">Name</span></td> <td width="78" class="style1"><span class="style5">Pledge</span></td> <td width="132" class="style1"><span class="style5">Points</span></td> <td width="194" class="style1"><span class="style5">Cost</span></td> <td width="78" class="style1"><span class="style5">Kwh</span></td> <td width="78" class="style1"><span class="style5">Carbon</span></td> <td width="72" class="style1"><span class="style5">Classification</span></td> <td width="150" class="style1"><span class="style5">Energy Saving</span></td> <td width="91" class="style1"><span class="style5">Enabled</span></td></strong> </tr> <p class="style1"> <? //This is only displayed if they have submitted the form if ($searching =="yes") { echo "<h2>Results</h2><p>"; //If they did not enter a search term we give them an error if ($find == "") { echo "<p>Please enter a search term"; exit; } // Otherwise we connect to our Database mysql_connect('localhost','admin','pass') or die(mysql_error()); mysql_select_db("table") or die(mysql_error()); // We preform a bit of filtering $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); //Now we search for our search term, in the field the user specified $results = mysql_query("SELECT * FROM table WHERE upper($field) LIKE'%$find%'"); //And we display the results while ($a = mysql_fetch_array($results)) { echo'<TR> <TD>'.$a['id'].'</TD> <TD>'.$a['name'].'</TD> <TD>'.$a['pledge'].'</TD> <TD>'.$a['points'].'</TD> <TD>'.$a['cost'].'</TD> <TD>'.$a['kwh'].'</TD> <TD>'.$a['carbon'].'</TD> <TD>'.$a['classification'].'</TD> <TD>'.$a['energysaving'].'</TD> <TD>'.$a['enabled'].'</TD> </TR>'; }; print("</TABLE>"); } else { print("No results to display"); }; //This counts the number or results - and if there wasn't any it gives them a little message explaining that { echo ""; } ?> I'm very sure I have the database connection correct but it just doesn't seem to display any results. Thank you for your replies in advance. Michael Quote Link to comment https://forums.phpfreaks.com/topic/186655-search-function-does-not-work-please-help/ Share on other sites More sharing options...
vinpkl Posted December 30, 2009 Share Posted December 30, 2009 your <form> action is incorrect. replace <form action="<?=$PHP_SELF?>" method="post" name="search" class="style1"> with <form action="<?php echo $PHP_SELF;?>" method="post" name="search" class="style1"> vineet Quote Link to comment https://forums.phpfreaks.com/topic/186655-search-function-does-not-work-please-help/#findComment-985798 Share on other sites More sharing options...
oriental_express Posted December 30, 2009 Author Share Posted December 30, 2009 Thank you but still no luck Quote Link to comment https://forums.phpfreaks.com/topic/186655-search-function-does-not-work-please-help/#findComment-985800 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.