Log in

View Full Version : Php Form To change Mysql Query



danbb
04-25-2010, 09:23 AM
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

$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 :




<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!

kuau
04-25-2010, 04:08 PM
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. :)

djr33
04-25-2010, 06:15 PM
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?