check for a particular value in a db field

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
glennn3
Forum Commoner
Posts: 63
Joined: Sat Sep 20, 2003 8:43 pm

check for a particular value in a db field

Post 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
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

if ($result[free] == "0"){
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post 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
?>
glennn3
Forum Commoner
Posts: 63
Joined: Sat Sep 20, 2003 8:43 pm

Post by glennn3 »

yes, thanks...
Post Reply