Php – Warning: thesqli_query() expects parameter 1 to be thesqli, string given in

mysqliPHP

I got the warning:

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in (…) on line 6

My code is here:

<?php

require_once 'conn.php';

$sql = "SELECT user_id, access_lvl, name FROM cms_users ";
$result = mysqli_query($sql, $conn);

Best Answer

It's exactly as the error states as you're passing arguments to mysqli_query() incorrectly. Assuming $conn is your mysqli connection generated at some point by new mysqli() it should be:

$result = mysqli_query( $conn,$sql) or trigger_error(mysqli_error($conn)));

The way you were calling it you were passing a string, $sql as the first argument.

Related Topic