tags:

views:

48

answers:

2
$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.

A: 

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.

Jack M.
i forgot to select the db and connectthanks
orange
Take a look at @thetaiko's answer, as well. He has a good point which may show you the actual error you're encountering.
Jack M.
+1  A: 

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

thetaiko
thanks again! I missed that one :)
orange