Results 1 to 12 of 12

Thread: How to check for empty string and empty search type?

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    How to check for empty string and empty search type?

    Hi all . I wonder how make sure the user selected search type m and typed search term s. If they do not i post them this massage along with search box again and rest of scrip does not run:

    ::: Invalid Search :::

    You can not search for empty string, your search word must be at least 3 character long. Try again please



    Code:
    <table border="0" cellspacing="0" width="90%" id="table1"
    style="border-style:dashed&gt;
    	&lt;tr&gt;
    		&lt;td&gt;
    		&lt;p align="
    center">
        <tr>
            <td><b><i>::: Search </i></b><font color="#FF0000"><b><i>New</i></b></font>
            ::: <br>
            <form action="searchprocess.php" method="GET" name="form1">
                <p><input type="text" size="20" name="s">  </p>
    
    <select name="m">
    		    <option selected>Select a search type</option>
    <option value="artist">Search By Artist</option>
    <option value="title">Search By Title</option>
    <option value="album">Search by Album</option>
    
              </select>
    <input
                type="submit" > </p>
            </form>
            </td>
        </tr>
    </table>
    PHP PART
    PHP Code:

    <?
    error_reporting(E_ALL); 

    $m   = $HTTP_GET_VARS['m'];

    $s   = $HTTP_GET_VARS['s'];



    switch ($m){
     case "title": 
    $query  = "select id,artist,album,songname from musictest where songname like '%$s%'";
      break;
     case "album": 

    $query  = "select DISTINCT album, artist from musictest where album like '%$s%' ";

      break;
     case "artist": 
     $query  = "select DISTINCT artist from musictest where artist like '%$s%' ";
      break;
    }

    $result = mysql_query($query);
    if (! ($result = mysql_query($query))) {
        echo(mysql_error());
        exit;
    }
    ?>
    standred html for page view and using switch to setup diffrent table for 
    each type of search
    <html>
    <head>
    <link rel="stylesheet" type="text/css" href="./default.css">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title> </title>
    </head>
    <body topmargin="0" leftmargin="0" ONLOAD="preloadImages();">

    .....
    .....
    <? switch ($m):case "title": ?>
     <tr><tr>
            <td width="5%"><b>#</b></td>
            <td width="30%"><b>Song</b></td>
            <td width="20%"><b>In Album</b></td>
            <td width="20%"><b>By Singer</b></td>
            
        </tr>

    .....
    .....

    <? endswitch; ?>

    <?
    $numbers=0;
    while($row = mysql_fetch_assoc($result))
    {

     // again usage of switch for each type of serach type output to make the table 
    ....
    ....
    <? endswitch; ?>

    <?


    } // end of while loop


    ?>


    <?
    switch ($m):
     case "title": ?>

      </table>


     <? break;
     case "artist": ?>
        
    </table>
     <? break;
     case "album": ?>
         </table>
    <? break;
     default: ?>
     this is some default html

    <? endswitch; ?>

    </body>

    </html>
    Last edited by tony007; May 24th, 2006 at 12:18 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width