Results 1 to 3 of 3

Thread: Php Form To change Mysql Query

  1. #1
    Join Date
    Apr 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Php Form To change Mysql Query

    Hello.

    Im trying to build a php form (drop down) that will change my mysql query, some kind of a filter.

    this is my php code :

    PHP Code:
    <?php

    $username
    ="***";
    $password="****";
    $database="****";

    mysql_connect(localhost,$username,$password);
    @
    mysql_select_db($database) or die( "Unable to select database");

    if (isset(
    $_GET['subject'])) 

    switch(
    $_GET['subject']) 

    case 
    'field1'
    $query "select * from employees where email LIKE '%$field1%'"
    break; 
    case 
    'field2'
    $query "select * from employees where email LIKE 'field2' "
    break; 
    default: 
    echo 
    'No subject found'
    $query false

    }


    if (
    $query){ 
    $result=mysql_query($query); 
    $numrows=mysql_num_rows($result); 


    $i=0;
    while (
    $i $num) {

    $f1=mysql_result($result,$i,"last_name");
    $f2=mysql_result($result,$i,"tests");
    $f3=mysql_result($result,$i,"email");
    $f5=mysql_result($result,$i,"hire_date");
    ?>

    <tr>
    <td><font face="Arial, Helvetica, sans-serif"><?php echo $f1?></font></td>
    <td><font face="Arial, Helvetica, sans-serif"><?php echo $f2?></font></td>
    <td><font face="Arial, Helvetica, sans-serif"><?php echo $f3?></font></td>
    <td style="width: 80px;"><font face="Arial, Helvetica, sans-serif"><?php echo $f5?></font></td>
    </tr>


    <?php
    $i
    ++;
    }
    ?>

    and this is the form :

    Code:
    <form name="form" action="<? print $_SERVER['PHP_SELF']?>" method="get">
    
    <select name="subject"> 
    <option value=""></option> 
    <option value="תל אביב">תל אביב</option> 
    <option value="field2">תל אביב</option> 
    </select>
    
    <input type="submit" name="Submit" /> 
    </form>
    thank you very much for your help!

  2. #2
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    If that is a copy and paste from your form, no wonder it doesn't work. Am I the only one seeing those non-ASCII characters? Perhaps your code got corrupted somehow, unless you are writing it in swahili.

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I believe that's hebrew. There's no reason that won't work, BUT it looks like you're trying to match field1 and field2, but the form has values of תל אביב and field2. Fix that and it'll work?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

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