brucieboy22 Posted March 2, 2008 Share Posted March 2, 2008 Hi, I'm a novice when it comes to PHP. I have tried to run the below within PHP5, but for some reason the behavious is wrong. The code doesn't execute. It's obviously a type of some sorts, but under PHP4 it works fine. Any help would be appreciated. <form name="search" method="post" action="<?=$PHP_SELF?>"> <select name="field"> <option value="Artist" name="artist">Artist</option> <option value="Label" name="label">Label</option> <option value="Title" name="title">Title</option> </select> <input type="text" size="25" name="find"> <input type="hidden" name="searching" value="yes"> <input type="submit" name="search" value="Search"> </form> <?php //This is only displayed if they have submitted the form if ($searching == "yes") { //If they did not enter a search term we give them an error if ($find == '') { echo "<div align=\"center\"><strong>You forgot to enter a search term</strong></div>"; exit; } etc, ..... Quote Link to comment https://forums.phpfreaks.com/topic/93993-form-wont-work-in-php5/ Share on other sites More sharing options...
monkeybidz Posted March 2, 2008 Share Posted March 2, 2008 <?php if ($_POST['searching'] == 'yes') { //If they did not enter a search term we give them an error if ($_POST['find'] == "") { print "<div align=\"center\"><strong>You forgot to enter a search term</strong></div>"; exit; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/93993-form-wont-work-in-php5/#findComment-481543 Share on other sites More sharing options...
brucieboy22 Posted March 2, 2008 Author Share Posted March 2, 2008 Many thanks monkeybidx for the promt reply. This fixed the code, I've now got another problem and attach the entire piece. It now 'blows up' about :- mysql_num_rows(): supplied argument is not a valid MySQL result resource, and mysql_fetch_array(): supplied argument is not a valid MySQL result resource <?php //This is only displayed if they have submitted the form if ($_POST['searching'] == "yes") { //If they did not enter a search term we give them an error if ($_POST['find'] == '') { echo "<div align=\"center\"><strong>You forgot to enter a search term</strong></div>"; exit; } // 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 $data = mysql_query("SELECT *,DATE_FORMAT(Released, '%M %Y') AS date FROM music_data WHERE upper($field) LIKE '%$find%'"); //This counts the number or results $anymatches=mysql_num_rows($data); if ($anymatches == '0') { echo "<div align=\"center\"><strong>Sorry, but I can not find any records to match your query of $find</strong></div><br><br>"; } elseif ($anymatches >= '1') { print " <p align=\"center\"><strong>I found $anymatches record(s) matching your search of $find</strong></p>"; } //And we display the results while($result = mysql_fetch_array( $data )) { $title = $result['Title']; etc, ... Sorry to be a pain :-) Quote Link to comment https://forums.phpfreaks.com/topic/93993-form-wont-work-in-php5/#findComment-481560 Share on other sites More sharing options...
wildteen88 Posted March 2, 2008 Share Posted March 2, 2008 You most probably have an error within your query, change this line: $data = mysql_query("SELECT *,DATE_FORMAT(Released, '%M %Y') AS date FROM music_data WHERE upper($field) LIKE '%$find%'"); To: $data = mysql_query("SELECT *,DATE_FORMAT(Released, '%M %Y') AS date FROM music_data WHERE upper($field) LIKE '%$find%'") or die(Query error: ' . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/93993-form-wont-work-in-php5/#findComment-481561 Share on other sites More sharing options...
brucieboy22 Posted March 2, 2008 Author Share Posted March 2, 2008 Thanks wildteen88, sorry to be such a plank. The error I now get is : Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') LIKE %%' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/93993-form-wont-work-in-php5/#findComment-481583 Share on other sites More sharing options...
AndyB Posted March 2, 2008 Share Posted March 2, 2008 $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); should be: $find = trim(strip_tags(strtoupper($_POST['find']))); Quote Link to comment https://forums.phpfreaks.com/topic/93993-form-wont-work-in-php5/#findComment-481590 Share on other sites More sharing options...
brucieboy22 Posted March 4, 2008 Author Share Posted March 4, 2008 thanks for everyone's help. I've now cracked this Quote Link to comment https://forums.phpfreaks.com/topic/93993-form-wont-work-in-php5/#findComment-482852 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.