Mysqli_query() expects parameter 1 to be mysqli

I havent touched php for a very long while, but have a little issue with the code below thats bringing up the errors, but all seems fine to me, I cant work it out.

$db="1";
$host="2";
$user="3";
$pass="4";

$link=mysqli_connect($host,$user,$pass,$db);

$q=mysqli_query($link, "select TID, TITLE, DATE, PIC, ATTACHMENT, DESCRIPTION FROM TCOACHING WHERE (ACTIVE=1) AND (TITLE=1) ORDER BY TID DESC");	
while($g=mysqli_fetch_assoc($q)){ 
$id = $g['TID'];
$name = $g['TITLE'];
$date = $g['DATE'];
$pic = $g['PIC'];
$attachment = $g['ATTACHMENT'];
$description = $g['DESCRIPTION'];

Errors

Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /home/hp3-linc3-nfs1-x/053/938053/user/htdocs/junior-coaching.php on line 139

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in /home/hp3-linc3-nfs1-x/053/938053/user/htdocs/junior-coaching.php on line 140

Your connect command failed. Investigate the reason.

if (!$link) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}
2 Likes

If ever the connect is not a problem double check the select statement your column fields spelling

Hope it hepls

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.