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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.