ram ram - 11 days ago 6x
PHP Question

What does this mean mysqli_query() expects parameter 1 to be mysqli?

Gives me an error stating mysqli_query() expects parameter 1 to be mysqli, dont know what parameter is missing?

$item_id = 1001; $quantity=5;

$mysql_host = 'localhost';

$conn=mysql_connect($mysql_host,$mysql_user_name,$mysql_user_password,$db) or die("could not connect to mysql");;

$sql = "INSERT INTO cart (item_id,qty)VALUES ('$item_id','$quantity')";

$query = mysqli_query($conn, $sql) or die(mysqli_error($conn));

if (query === TRUE)
echo "New record created successfully";
echo("Error description: " . mysqli_error($conn));// gives an error here



You are connecting with mysql_ and trying to query using mysqli_. The two are totally separate and cannot be mixed.

Use something like this:

$mysqli = new mysqli('', 'your_user', 'your_pass', 'db_name');

$sql = sprintf("INSERT INTO cart (item_id,qty) VALUES ('%d','%d')", $item_id, $quantity);
$result = $mysqli->query($sql);