2

Hello i have tryed many ways to get this to work am unsure where my error is. i get the Error message.

mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in

This is the Code:

$dbh = mysqli_connect("HOST", $user_name, $password, $database_name);
if (!$dbh)
{
    die("Not connected : " . mysqli_error($dbh));
}

if ($method=="graces")
{ 
   $query = "SELECT id, name FROM raceslog";
    $userinfo = array();

      while ($row_user = mysql_fetch_assoc($query)){
       $userinfo[] = $row_user;}

       foreach ($userinfo as $user) {
         echo "^{$user[id]}"
            . "^{$user[name]}";
        }
 }  

Well my question is does anyone see where my error is and could point me in the right direction to fix Thank You.

1 Answer 1

2

You need to actually run the query first with mysqli_query. Also note that mysql_* and mysqli_* are not compatible. You should stick with mysqli and properly parameterize your queries.

$result = mysqli_query($dbh, $query);
while ($row_user = mysqli_fetch_assoc($result)) {

You can also echo in the while loop if you want.

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

Comments

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.