mardi 28 juillet 2015

SQL where clause giving a null result

I have the following simple php code that gives me a result that I want to display.

$linkz= mysql_connect($host,$username,$password) or die(mysql_error());
mysql_select_db($db, $linkz);


$sq_name= $_POST['unameTF'];
$sq_pass= $_POST['passTF'];
$sq_search= $_POST['searchTF'];

if($sq_search=""||$sq_search=null)
{
echo "type something";
}else
{
$sql2= "SELECT * FROM sql_insert WHERE sq_name='$sq_search' ";
$res= mysql_query($sql2, $linkz) or die(mysql_error());
}

    while($row=mysql_fetch_assoc($res))
    }
    echo "$row[sq_name]"."<br/>";
    }

This gives me a null result always(ie it doesn't give an error or dispay anything). It works fine when the if-else statement is removed meaning it just

$sql2= "SELECT * FROM sql_insert WHERE sq_name='$sq_search' ";
$res= mysql_query($sql2, $linkz) or die(mysql_error());

and no checking to see if its null.

and also if I replace

$sql2= "SELECT * FROM sql_insert WHERE sq_name='$sq_search' ";

with

$sql2= "SELECT * FROM sql_insert WHERE sq_name='".$_POST['searchTF']."' ";

(even without removing the if-else statement)

Can someone explain whats going on?

Aucun commentaire:

Enregistrer un commentaire