0
$sqlQuery = "SELECT * FROM allowedUsers WHERE UserID = '" . $kUserID . "'";
$result=mysql_query($sqlQuery, $db);
if(!result)
{
    echo "Error running query <br>" . mysql_error();
    exit;
}
while($row = mysql_fetch_array($result))
{
    echo $row[2];
}

I run the SQLQuery in phpMyAdmin and I am getting a valid result (1 row) the table (allowedUsers) has 6 fields I can't get anything out of the DB.

Any help is appreciated.

1
  • The code looks fine. Is there really no output in $row? Are you sure the user ID exists? Commented Feb 24, 2010 at 14:55

2 Answers 2

1

if(!result) should be if(!$result)

Sign up to request clarification or add additional context in comments.

Comments

0

According to PHP.net's documentation, you don't need to pass $db to mysql_query(). Take a look at the example code:

<?php
    mysql_connect("localhost", "mysql_user", "mysql_password") or
        die("Could not connect: " . mysql_error());
    mysql_select_db("mydb");

    $result = mysql_query("SELECT id, name FROM mytable");

    while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
        printf("ID: %s  Name: %s", $row[0], $row[1]);  
    }

    mysql_free_result($result);
?>

It may be helpful to see your connection code, ensure you've selected a database, etc.

1 Comment

Take a look at @thetaiko's answer, as well. He has a good point which may show you the actual error you're encountering.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.