Hi I am newbie to PHP. I just wanted to create a registration page for students. In that page I've populated checkboxes for students who wants to enroll more than one classes. Everything got done. But I'm stuck with the final phase of this idea. I just wanted to save data in 2 tables with single submit. Tables names ('data' table for student details, 'stud_class' table for student_id with class_id)One is for only students details and the another is for saving selected checkboxes(classes) in the same registration form. Sorry! I don't know what exactly the technical term is as of my knowledge it's detail table. Because student may select n number of checkboxes. I just want to save one row in 'data' table for student other details and fetch the id of that inserted line from 'data' table and save it to stud_class table with selected checkboxes id's. I mean stud_id should multiple with selected unique checkboxes id's. My output should look like this (stud_id, class_id) (For Ex : stud_001 1, stud_002 5, stud_002 2, stud_002 3, stud_003, 6) and save it to 'stud_class' table.
$checkbox1 = $_POST['classes'];
for( $i=0 ; $i<count($checkbox1); $i++){
//$query = "insert into stud_class (stud_id) select max(id) from data";
//$query = "insert into stud_class (class_id) values ('".$checkbox1[$i]."')";
$query = "insert into stud_class (class_id,stud_id) values ('".$checkbox1[$i]."',select max(id) from data)";
mysql_query($query) or die (mysql_error());
}
echo "Record Inserted";
I tried to save individual fields in to the stud_class table commented lines in the above code. It's works fine. But I want to save both in single query as I tried in
$query = "insert into stud_class (class_id,stud_id) values ('".$checkbox1[$i]."',select max(id) from data)";
this line. Anyone help me please to achieve this. And please let me know what problem in this above line. Thanks in advance.