Morgan Green
Morgan Green

Reputation: 996

Parameter error with Mysqli

When I run this Query I recieve

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/morgan58/public_html/wow/includes/index/index_admin.php on line 188
SELECT * FROM characters WHERE id=5
Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given in /home/morgan58/public_html/wow/includes/index/index_admin.php on line 194

The Query is running and it is strying to select the correct information, but for on the actual output it's giving me a fetch_array error; if anyone can see where the error lies it'd be much appreciated. Thank you.

<?php
  $adminid= $admin->get_id();
  $characterdb= 'characters';
$link = mysqli_connect("$server", "$user", "$pass", "$characterdb");
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
$query = "SELECT * FROM characters WHERE id=$adminid";
$result = mysqli_query($link, $query);
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
echo $query;
echo $row['name'];
}
mysqli_free_result($result);
mysqli_close($link);
?>

Upvotes: 0

Views: 71

Answers (2)

justnajm
justnajm

Reputation: 4534

$query = "SELECT * FROM characters WHERE id=$adminid";
//further correction is single quote your variable in this case you are increase success run of your query
$query = "SELECT * FROM characters WHERE id='$adminid'";

$result = mysqli_query($link, $query);

// its good you check before you leap
if($result){
    // your process
} else {
    echo "Unable to find given admin id";
}

Upvotes: 0

Ibu
Ibu

Reputation: 43810

There is an error in your query, so mysqli_query() is returning false. Check if it is valid before using it:

if ($result) {
    /// your code
}else {
    // your query failed
    die("Error: ".mysqli_error($link)); // will print your error
}

Upvotes: 3

Related Questions