1

Today I'm trying to update a value on a DB based on MySql and I'm trying to do it with prepared statement but i don't know why it's not working... the code is the follow:

    if(isset($_POST['venditore']) && $_POST['venditore'] == 'on'){ // "venditore" is a checkbox
        if ($stmt = $con->prepare('UPDATE accounts SET venditore = ? WHERE username = ?')) {
            $stmt->bind_param('is', 1, $_SESSION['name']); // This is line 64
            $stmt->execute();
            header('location: ../profile.php?successo');
        }else{
            header('location: ../profile.php?errore');
        }
    }else{
        header('location: ../profile.php');
    }

I'm not an expert but i don't see any problem in there... but it throw me this error:

Fatal error: Uncaught Error: Cannot pass parameter 2 by reference in D:\xampp\htdocs\Lavoro\lang\en\login\authenticate.php:64 Stack trace: #0 D:\xampp\htdocs\Lavoro\lang\en\login\authenticate.php(16): Venditore() #1 {main} thrown in D:\xampp\htdocs\Lavoro\lang\en\login\authenticate.php on line 64

Could enyone explain me that please?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Elizzit
  • 11
  • 3

1 Answers1

2

The error says it. You can not pass parameters by reference to the bind_param method. See PHP docs here. Solution is simple - just create new variables:

$number = 1;
$name = $_SESSION['name'];
$stmt->bind_param('is', $number, $name);

Also, I recommend using PDO for prepared statements, it is easier for you.

CreeperMaxCZ
  • 135
  • 8