Wow this code is driving me insane.
My problem is getting two arrays into a multiple INSERT query. I can't seem to
find a way for the loop to insert both arrays.
$sql_data = array();
$sql_prefix = "INSERT INTO student_score(course_uid, student_uid, question_uid, answer) VALUES";
foreach($_POST['answer'] as $id => $answer){
// don't use $_REQUEST!
$course_id = (int) $_POST['course_id'][$i];
$student_id = (int) $_POST['student_id'][$i];
$question_id = (int) $_POST['question_id'][$i];// This turns out 0
$answer = mysql_real_escape_string($answer);
$sql_data[] = "($course_id, $student_id, $question_id, '$answer')";
foreach ($_POST['question_id'] as $question_id) {
// var_dump($question_id);//there are 2 value in here
}
}
$sql = $sql_prefix.implode(", \n", $sql_data);
//var_dump($sql);
if(!mysql_db_query($dbName, $sql, $connect)){
$_SESSION['msg'] = "Could not save information, Please try again";
header("Location:student_assignment.php");
//replaced die with else clause
}
else{
$_SESSION['msg'] = "Question successfully created";
header("Location:student_assignment.php");
}
Can someone please help me