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 ) {

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

                if ( false===$rc ) {

                $rc = $stmt->execute();

                if ( false===$rc ) {


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 :)

Recommended Answers

All 2 Replies

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.

As usual, Pritaeas saves the day.

Hey again and thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.