buds2000 Posted June 28, 2007 Share Posted June 28, 2007 what i want to do is select from a drop down box OR type a search string on the same form. IE; <form action="searchall.php" method="POST"> <select name="srch"> <option value="" selected="selected"></option> <option value="rock">Rock</option> <option value="pop">Pop</option> <option value="country">Country</option> <option value="ballad">Ballad</option> <option value="uptempo">Up Tempo</option> <input type="text" name="srch" value="" size="30"> <input type="Submit"> </form> I have an error check that will check to see if the string is empty: if ($srch) // perform search only if a string was entered. Should i just remove the error check? If i type in the string the action works, but if i choose from the drop down i get the error. Quote Link to comment Share on other sites More sharing options...
no_one Posted June 28, 2007 Share Posted June 28, 2007 I don't know to much about html.. I'd think 'names' have to be unique? That is, the 'text' box having srch replaces the select as 'srch'. Maybe giving them both different names and checking if text exists, if not then check selection? Maybe showing the error would help a bit more here. Sorry if I didn't help any. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted June 28, 2007 Share Posted June 28, 2007 Just check which search type the user searched with: <?php if (!empty($_POST['srch'])){ //Put code here that searches according to the select box. } else if (!empty(trim($_POST['srch2']))){ //Put code here that searches according to what the user puts in the text box. } ?> <form action="searchall.php" method="POST"> <select name="srch"> <option value="" selected="selected"></option> <option value="rock">Rock</option> <option value="pop">Pop</option> <option value="country">Country</option> <option value="ballad">Ballad</option> <option value="uptempo">Up Tempo</option> </select> <input type="text" name="srch2" value="" size="30"> <input name="submit" value="submit" type="submit"> </form> Quote Link to comment Share on other sites More sharing options...
redarrow Posted June 28, 2007 Share Posted June 28, 2007 I agree you can not use the same select name as a name for a input box. all you do is chage one or the other. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 28, 2007 Share Posted June 28, 2007 why you even want the same. Input names are designed to give unqueness to inputs so you can retrive them on the process page Quote Link to comment Share on other sites More sharing options...
buds2000 Posted June 28, 2007 Author Share Posted June 28, 2007 The reason i want to use the same name (srch) is because of the line below. $query = "select * from catalog WHERE w1 LIKE '$srch' || w2 LIKE '$srch' || w3 LIKE '$srch' || w4 LIKE '$srch' || pubtag LIKE '$srch'"; Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted June 28, 2007 Share Posted June 28, 2007 well just add in the same thing except for $srch2. $query = "select * from catalog WHERE w1 LIKE '$srch' OR w2 LIKE '$srch' OR w3 LIKE '$srch' OR w4 LIKE '$srch' OR pubtag LIKE '$srch' OR w1 LIKE '$srch2' OR w2 LIKE '$srch2' OR w3 LIKE '$srch2' OR w4 LIKE '$srch2' OR pubtag LIKE '$srch2'"; that wasnt so hard, was it? 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.