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
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.
Link to comment
Share on other sites

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??
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.