0

Hey! Long time no speak ^.^

I've been trying to make a query which would follow this logic (Which works in phpMyAdmin):

UPDATE member_food SET food_id=12 WHERE member_id=4 AND food_type="breakfast"

However, when I do it in PHP:

$sql_breakfast1 = "UPDATE member_food SET food_id ='$breakfast1' WHERE member_id='$id'    AND food_type='breakfast'";
if ($mysqli->query($sql_breakfast1) === TRUE) {
echo "Query: " . $sql_breakfast1;
} else {
    echo "Query: " . $sql_breakfast1 . "<br> Error: " . $mysqli->error;
}

When I navigate to this page after using my forms, I get this echo:

Query: UPDATE member_food SET food_id ='8' WHERE member_id='5' AND food_type='breakfast'

So, it is getting the information from my form... But in my database it sets the food_id to 1.

I've tried doing this:

$sql_breakfast1 = "UPDATE member_food SET food_id =? WHERE member_id=?  AND food_type=?";
                $stmt = $mysqli->prepare($sql_breakfast1);

                if ( false===$stmt ) {
                  die($mysqli->error);
                }

                $rc = $stmt->bind_param('sis', $breakfast1, $id, 'breakfast');

                if ( false===$rc ) {
                  die($stmt->error);
                }

                $rc = $stmt->execute();

                if ( false===$rc ) {
                  die($stmt->error);
                }

                $stmt->close();

But I get the error: Fatal error: Cannot pass parameter 4 by reference on this line: $rc = $stmt->bind_param('sis', $breakfast1, $id, 'breakfast');

Thanks :)

2
Contributors
2
Replies
15
Views
2 Years
Discussion Span
Last Post by bradly.spicer
1

Cannot pass parameter 4 by reference

It expects a variable, so you cannot pass the string 'breakfast' directly. So, either put it in the query (as it's not really a parameter), or put it in a variable.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.