0

When i delete my items from my cart this error shows;

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\xampp\htdocs\FinalsActivity1\delete.php on line 5

Warning: mysqli_error() expects parameter 1 to be mysqli, string given in C:\xampp\htdocs\FinalsActivity1\delete.php on line 5

**CODES

 <?php
    require("config.php");
    require('header.php');
   ***LINE 5*** $itemsql = "SELECT * FROM orderitems WHERE id = ". $_GET['id'] . ";";
    $itemres = mysqli_query($dbdatabase, $itemsql) or die(mysqli_error($itemsql));
    $numrows = mysqli_num_rows($itemres);
    if($numrows == 0) {
    header("Location: showcart.php");
    }
 . 

1 Answer 1

0

Surround your variables in quotes. In your example, it would be:

$itemsql = "SELECT * FROM orderitems WHERE id = '". $_GET['id'] . "';";

And

$prodsql = "SELECT price FROM products WHERE id = '" . $itemrow['product_id'] . "';";

This is because, assuming, your ID's are actually ints therefore when you're placing them in the query without quotes it's handling them as an int. By surrounding them in quotes it forces the query to interpret it as a string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.