Page 1 of 1

check for a particular value in a db field

Posted: Sat Jan 17, 2004 1:03 am
by glennn3
newbie here - i simply want to check for a 1 or a 0 in field "free" - if "0" go there, if "1" stay here...

Code: Select all

$sql = "SELECT free FROM user WHERE username = 'glennn' ";
$result = mysql_query($sql);

 if ($result == "0"){
 print("<script language="javascript">
top.location="test.php";
</script>");
  &#125;
it don't work... (my db connection is good...)

anybody?
thanks ,
glenn

Posted: Sat Jan 17, 2004 2:40 am
by kettle_drum
if ($result[free] == "0"){

Posted: Sat Jan 17, 2004 6:25 am
by Bill H
Well, actually:

Code: Select all

<?php
$sql = "SELECT free FROM user WHERE username = 'glennn' "; 
$result = mysql_query($sql); 
$row = mysql_fetch_array($result);
if ($row['free'] == 0){         // if checking for numeric value don't use quotes
     // etcetera                        if a literal value do use quotes
?>

Posted: Sat Jan 17, 2004 9:54 am
by glennn3
yes, thanks...