Jump to content

Can I do This?


buds2000

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/57493-can-i-do-this/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/57493-can-i-do-this/#findComment-284461
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/57493-can-i-do-this/#findComment-284463
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/57493-can-i-do-this/#findComment-284578
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.