Jump to content

Searchbox with 2 vars doesn't work right..


gladz0r

Recommended Posts

Hello there

 

I've made a script that shows database entries filtered by a searchbox.

The problem is that the 2 HTTP_POST_VARS don't cooperate.

For example when you choose 'Leerjaar' -> '1ste leerjaar' and 'Vak' -> 'Wiskunde' it has to show the entries of '1ste leerjaar' that have 'Vak' = Wiskunde.

 

See the website at http://sbshasselt.be/ictco/maarten/htdocs/

 

Script

Searchbox

    echo "<HTML>\n
    <HEAD><TITLE>Filter</TITLE></HEAD>
    <BODY>
    
  
    <p>
    <FORM METHOD=\"POST\" ACTION=\"index.php\">
    <b>Filter op leerjaar:</b><br>
    <select name=\"leerjaar\" id=\"leerjaar\">
	      <option>   </option>
      <option>1ste kleuter</option>
          <option>2de kleuter</option>
          <option>3de kleuter</option>
          <option>1ste lager</option>
          <option>2de lager</option>
          <option>3de lager</option>
          <option>4de lager</option>
          <option>5de lager</option>
          <option>6de lager</option>
</select>
<b>Vak</b><br>
<select name=\"vak\" id=\"vak\">
	      <option>   </option>
      <option>Taal</option>
          <option>Wiskunde</option>

</select>
    <input type=\"submit\" name=\"submit\" value=\"Zoeken\">
    </p>
    
    </BODY>
    </HTML>";

Page

      <?php include("zoek2.php"); ?>
<table width="100%" border="1"> 
<tr> 
<td width="50px" class="style7"><b><p class="style3">Leerjaar</p></b></td> 
<td width="50px" class="style7"><b><p class="style3">Vak</p></b></td> 
<td width="50px" class="style7"><b><p class="style3">Lesonderwerp</p></b></td> 
<td width="50px" class="style7"><b><p class="style3">Doelstelling</p></b></td> 
<td width="20px" class="style7"><b><p class="style3">IN</p></b></td> 
<td width="50px" class="style7"><b><p class="style3">Media</p></b></td> 
</tr>
<?php 
  $sql = "SELECT * FROM `formulier` WHERE (`leerjaar` LIKE '%$HTTP_POST_VARS[leerjaar]%' AND 'vak' LIKE '$HTTP_POST_VARS[vak]%')";
  $qSelect_berichten  = mysql_query($sql) or die (mysql_error()); 
  while($aBerichten = mysql_fetch_array($qSelect_berichten)) 
    { 
      echo '<tr> 
              <td width="50px"><p class="style4">'.$aBerichten['leerjaar'].'</p></td> 
		  <td width="50px"><p class="style4">'.$aBerichten['vak'].'</p></td> 
		  <td width="50px"><p class="style4">'.$aBerichten['lesonderwerp'].'</p></td> 
<td width="30%"><p class="style4">'.$aBerichten['doelstelling'].'</p></td> 
<td width="20px"><p class="style4">'.$aBerichten['ict'].'</p></td> 
<td width="30%"><p class="style4"><a href="'.$aBerichten['ict2'].'">1</a></p></td> 

            </tr>'; 
    } 
     echo '</table>'; 
   } 

 

Link to comment
Share on other sites

You need to give your option tags a value attribute. For example:

 

<select name = "selectfield">
<option value = "the value">The text displayed on screen</option>
...
</select>

 

The user will see the text between the opening and closing tag ("The text displayed on screen", in this example), whilst it will be the text in the value attribute that is sent to the server("the value", in this case).

 

Oh. $HTTP_POST_VARS is depreciated(and has been for quite a while). You should be using $_POST instead.

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.