1

I have a group of checkboxes each with the name attribute "question_id[]". Additionally I have a selectbox that passes a singular value of survey_id. These values are passed via the form to:

$survey_id= $_POST['survey_id'];

foreach($_POST['question_id'] as $question_id) {

    $sql=("INSERT INTO questions_questionnaires (question_id, survey_id) VALUES ('$question_id', '$survey_id')");

    mysqli_query($con,$sql);

    if (!mysqli_query($con,$sql)) {
        die('Error: ' . mysqli_error($con));
    }

}

Each value in the 'question_id' array is being inserted twice into the DB. Any ideas?

1 Answer 1

2

You're calling mysqli_query twice:

mysqli_query($con,$sql);

if (!mysqli_query($con,$sql)) {
    die('Error: ' . mysqli_error($con));
}

Remove the first one (outside of the if) and it should be okay.

1
  • Can't believe I missed that! Not enough coffee this morning. Thanks. That did the trick. Commented Sep 29, 2014 at 19:25

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.