Jump to content

Am I getting the data from the query?


freshrod

Recommended Posts

I posted about this before and got an answer, but while it did stop the error, it still isn't working how I wanted. Basically I have a value in a DB field that I want to check. The column is set up like this:

'alumInfo enum ('0','1') NOT NULL default='0',

I query it like this:

$sql = mysql_query
("SELECT alumInfo FROM users WHERE username='$username' AND password='$password'");

Then I want to check what the value is. If it's 0 I want to print one thing, if it's 1 I want to print something else. I've tried something like this:

$row = mysql_fetch_array($sql); // I'm thinking the problem lies here...
if($row['alumInfo'] == '0') {
echo "one thing";
} else {
echo "something else";
}

It seems to ignore the first 'echo' and only prints the last one, even though the default value is '0'.
Any suggestions? Thanks.
Link to comment
https://forums.phpfreaks.com/topic/9056-am-i-getting-the-data-from-the-query/
Share on other sites

You never query the database.
[code]
if ($result = mysql_query($sql)) {
  $row = mysql_fetch_array($result);
  if (!$row['alumInfo']) {
    echo "one thing";
  } else {
    echo "something else";
  }
}
[/code]
Notice also this line... if (!$row['alumInfo']) {. 0 is false in php, so you dont need to do it the way you did. Besides, integers should not be quted as you had.
Actually thorpe, it would appear like he's using strings instead of integers. So the way he had it origionally should work, and he does query the database... it's above the output.

However, if you truly intend to use integers (0,1), you should change the table and the if statement if it is currently treating those as strings.

Are you sure any of the fields actually have 0 in them??

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.