Why does mysqli parameter binding give an error?

Viewed 44

I have a snippet of code as follows:

$sql = "INSERT INTO tasks
                (task_name, description, due_date, state, userID, importID)
                VALUES (?, ?, ?, ?, ?, ?)";
$stmt = mysqli_stmt_init($conn);
mysqli_stmt_bind_param($stmt, "sssiss", $name, $description, $due, 0, $_SESSION['userID'], $id);

When run in the browser, the browser does not load and a try catch statement does not work so I am not able to identify the exact error. I have an almost identical bit of code which works perfectly. The only difference is that this bit of code is in a for each loop. Will that have something to do with it?

EDIT: I forgot to mention all of this is in an if statement to prepare the statement.

if (!mysqli_stmt_prepare($stmt, $sql)) {
    header("Location: ../import.php?error=sqlinserterror");
    exit();
} else {
    mysqli_stmt_bind_param($stmt, "sssiss", $name, $description, $due, 0, $_SESSION['userID'], $id);
1 Answers

With bind_param you need to pass in parameter names, not values. Try:

mysqli_stmt_bind_param($stmt, "sssiss", $name, $description, $due, $zero, $user_id, $id);
$zero = 0;
$user_id = $_SESSION['userID'];
Related