deant Posted August 24, 2010 Share Posted August 24, 2010 Good day all, I am really in need of some help here with my website. I am new to the php and mysql environs, but an avid supporter and learner. I have a problem making my drop down 'category' option to work - as in when I select an option from the drop down list, it should pull the data from the mysql database which works magically with the keyword searches, etc...its just the category search not working - below is the coding which I am working with currently: action=search.php method=get> Keyword : <input type=text name=k /> Category : <select name=b> <option value=0>All</option> <?php $connection = mysql_connect('127.0.0.1', 'vale_view', '8hw9er1' ); if (!$connection) { die ("Could not connect to the database: <br />". mysql_error()); } $db_select=mysql_select_db('vale_view'); if (!$db_select) { die ("Could not select the database: <br />". mysql_error()); } $query = "SELECT catid,catname FROM categories order by catname"; $result = mysql_query( $query ) or die('die'); if (!$result) { die ("Could not query the database: <br />". mysql_error()); } while ($result_row = mysql_fetch_row($result)) { echo "<option value=".$result_row[0].">".$result_row[1]."</option>"; } mysql_close($connection); ?> Quote Link to comment https://forums.phpfreaks.com/topic/211572-php-option-echo-help/ Share on other sites More sharing options...
kenrbnsn Posted August 24, 2010 Share Posted August 24, 2010 Please reformat the code in your post to make it readable. Proper indentation. Enclose it in tags. Ken Quote Link to comment https://forums.phpfreaks.com/topic/211572-php-option-echo-help/#findComment-1102971 Share on other sites More sharing options...
MadTechie Posted August 24, 2010 Share Posted August 24, 2010 Tell me about it!!!! Here action=search.php method=get> Keyword : <input type=text name=k /> Category : <select name=b> <option value=0>All</option> <?php $connection = mysql_connect('127.0.0.1', 'vale_view', '[REMOVED]' ); if (!$connection) { die ("Could not connect to the database: <br />". mysql_error()); } $db_select=mysql_select_db('vale_view'); if (!$db_select) { die ("Could not select the database: <br />". mysql_error()); } $query= "SELECT catid,catname FROM categories order by catname"; $result = mysql_query( $query ) or die('die'); if (!$result) { die ("Could not query the database: <br />". mysql_error()); } while ($result_row = mysql_fetch_row($result)) { echo "<option value=".$result_row[0].">".$result_row[1]."</option>"; } mysql_close($connection); ?> </select> Also what you do mean by "not working" ? Quote Link to comment https://forums.phpfreaks.com/topic/211572-php-option-echo-help/#findComment-1102973 Share on other sites More sharing options...
deant Posted August 24, 2010 Author Share Posted August 24, 2010 I appreciate the input, what I mean by not working is this: On the web page itself, when I scroll onto the drop down menu list on 'categories' and then click on a category, thus displaying it in the box and then proceed to click on the 'search' button, it searches throughout the database (mysql), but wont give me the data which is listed under the category which I selected. It merely goes back to the first page of data pulled from the mysql database and thats it. I did try the code given, but doesnt help, it only makes the whole page dissapear with nothing on, but an error message. Any further suggestions? With appreciation, Dean Quote Link to comment https://forums.phpfreaks.com/topic/211572-php-option-echo-help/#findComment-1103037 Share on other sites More sharing options...
MadTechie Posted August 24, 2010 Share Posted August 24, 2010 The code "given" was your code but cleaned up! Also it sounds like you posted the drop down list that you just said was working!! So the broken code is ? Quote Link to comment https://forums.phpfreaks.com/topic/211572-php-option-echo-help/#findComment-1103041 Share on other sites More sharing options...
deant Posted August 24, 2010 Author Share Posted August 24, 2010 Okay, Thanks again for the quick feedback 'MadTechie'. I am glad to have this correspondence with you. It seems as though you get straight to the point and it's much appreciated. If I could ask you to go onto the website and check out what I mean: www.vale-view.co.za/search. Once on there you can test the drop down 'category' option and select a category, then proceed to click on the 'search' button - I'm sure you will get a better idea of what I am talking about and perhaps give a clearer perspective on this issue. Again, many thanks for the input, its a bit frustrating as everything seems to be set up, but probably just needs some tweaks on the coding....I can't tell. Kind Regards Dean Johannesburg Quote Link to comment https://forums.phpfreaks.com/topic/211572-php-option-echo-help/#findComment-1103260 Share on other sites More sharing options...
MadTechie Posted August 25, 2010 Share Posted August 25, 2010 The problem is, you have only posted the code that deals with the creating the Category drop down but what code run when you click search, is it possible to post the whole page or at least the part that handles the GET/POST requests Please make sure you put the code in-between code tags (click the # button) Quote Link to comment https://forums.phpfreaks.com/topic/211572-php-option-echo-help/#findComment-1103435 Share on other sites More sharing options...
deant Posted August 25, 2010 Author Share Posted August 25, 2010 Good day 'MadTechie', Thanks again. Below is the code involved for the category search. I think you are correct when you say that there is no GET / POST request for that, but only one for the keyword search, however I would like you to look at it in anycase just so every aspect is laid out. <form action=search.php method=get> Keyword : <input type=text name=k /> Category : <select name=b> <option value=0>All</option> <?php $connection = mysql_connect('127.0.0.1', 'vale_view', '8hw9er1' ); if (!$connection) { die ("Could not connect to the database: <br />". mysql_error()); } $db_select=mysql_select_db('vale_view'); if (!$db_select) { die ("Could not select the database: <br />". mysql_error()); } $query = "SELECT catid,catname FROM categories order by catname"; $result = mysql_query( $query ) or die('die'); if (!$result) { die ("Could not query the database: <br />". mysql_error()); } while ($result_row = mysql_fetch_row($result)) { echo "<option value=".$result_row[0].">".$result_row[1]."</option>"; } mysql_close($connection); ?> </select> Area : <select name=c> <option value=1>All</option> <option value=2>Bedfordview</option> <option value=3>Edenvale</option> </select> <input type=submit value='Search' /> </form> </td> </tr> Regards Dean Quote Link to comment https://forums.phpfreaks.com/topic/211572-php-option-echo-help/#findComment-1103492 Share on other sites More sharing options...
deant Posted August 25, 2010 Author Share Posted August 25, 2010 Hi Madtechie, Here is another line of coding falling beneath the coding which I sent previously on the same page. I'm not sure if this will be necessary to give you?? <?php $connection = mysql_connect('127.0.0.1', 'vale_view', '8hw9er1' ); if (!$connection) { die ("Could not connect to the database: <br />". mysql_error()); } $db_select=mysql_select_db('vale_view'); if (!$db_select) { die ("Could not select the database: <br />". mysql_error()); } if ($_GET['k']) { if ($_GET['b'] != '0') { if ($_GET['c'] != '1') { $query = "SELECT * FROM companies where compname like '%".$_GET['k']."%' and catid = ".$_GET['b']." and areaid = ".$_GET['c']." ORDER BY COMPNAME"; } else { $query = "SELECT * FROM companies where compname like '%".$_GET['k']."%' and catid = ".$_GET['b']." ORDER BY COMPNAME"; } } else { $query = "SELECT * FROM companies where compname like '%".$_GET['k']."%' ORDER BY COMPNAME"; } } else { $query = "SELECT * FROM companies ORDER BY COMPNAME LIMIT 20"; } $result = mysql_query( $query ) or die('die'); if (!$result) { die ("Could not query the database: <br />". mysql_error()); } echo "<table border=0px width=100%>"; while ($result_row = mysql_fetch_row($result)) { echo "<tr><td>".$result_row[1]."</td><td>".$result_row[2]."</td><td>".$result_row[3]."</td></tr>"; }?></table><br/><br/></font> </td> </tr> <tr> <td colspan=5 align=center valign=top> <font face='Calibri' size=2>Vale-View © Copyright 2010</font> </td> </tr></table></center></body></html> Regards Dean Quote Link to comment https://forums.phpfreaks.com/topic/211572-php-option-echo-help/#findComment-1103499 Share on other sites More sharing options...
trq Posted August 25, 2010 Share Posted August 25, 2010 Please reformat the code in your post to make it readable. Proper indentation. Enclose it in tags. Ken Quote Link to comment https://forums.phpfreaks.com/topic/211572-php-option-echo-help/#findComment-1103500 Share on other sites More sharing options...
fortnox007 Posted August 26, 2010 Share Posted August 26, 2010 lol Quote Link to comment https://forums.phpfreaks.com/topic/211572-php-option-echo-help/#findComment-1103842 Share on other sites More sharing options...
dgoosens Posted August 26, 2010 Share Posted August 26, 2010 You should pay attention with this kind of info: $connection = mysql_connect('127.0.0.1', 'vale_view', '8hw9er1' ); Everybody will be able access your DB now... Quote Link to comment https://forums.phpfreaks.com/topic/211572-php-option-echo-help/#findComment-1103843 Share on other sites More sharing options...
MadTechie Posted August 26, 2010 Share Posted August 26, 2010 You should pay attention with this kind of info: $connection = mysql_connect('127.0.0.1', 'vale_view', '8hw9er1' ); Everybody will be able access your DB now... IF remote access is allowed but yeah be warned Quote Link to comment https://forums.phpfreaks.com/topic/211572-php-option-echo-help/#findComment-1103867 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.