Hi there, i created 3 tables in mysql, which is college.students, college.classes, and college,student_in_class. After that, I made a web form (page) that lists all the current students, and lists all the current classes (each with a radio button). As a user, you can click on a student radio button, and a class radio button and that student becomes registered in that class (ie fill the "student_in_class" table.
I referred to your code and tried to apply to my module, but not much luck. Do u mind take a look of my code and tell me what did i do wrong? Much appreciated.... <?php # Global variables $script_name = 'register2.php'; $databasename = 'college'; $host = 'localhost'; $user = 'root'; $password = 'mollier'; function select_student() { # explicity request to use these global variables global $script_name, $databasename, $host, $user, $password; # connect to database $link = mysql_connect($host, $user, $password) or die("Connection failed: " . mysql_error()); # select our table mysql_select_db($databasename) or die("Database selection failed [$db_name]: " . mysql_error()); # send a query $sql = "SELECT * FROM college.students ORDER BY student_id"; $result = mysql_query($sql) or die("Query failed: " . mysql_error()); echo "<H2>Welcome to Class Selection Page</H2>\n"; echo "<FORM METHOD=POST ACTION=\"$script_name\">\n"; echo "<TABLE BORDER=1>\n"; # print the student selection table $table_row = "<TR>"; $table_row .= "<TH> </TH>"; $table_row .= "<TH>Students First Name</TH>"; $table_row .= "<TH>Students Last Name</TH>"; $table_row .= "<TH>Address</TH>"; $table_row .= "</TR>"; echo "$table_row\n"; while ($row = mysql_fetch_array($result)) { $table_row = "<TR>"; $table_row .= "<TD><INPUT TYPE=RADIO NAME=\"student\""; $table_row .= " VALUE=\"$row[student_id]\"></TD>"; $table_row .= "<TD>$row[firstname]</TD>"; $table_row .= "<TD>$row[lastname]</TD>"; $table_row .= "<TD>$row[address]</TD>"; $table_row .= "<TR>"; echo "$table_row\n"; } echo "</TABLE>\n"; echo "</FORM>\n"; mysql_free_result($result); mysql_close($link); } function select_class() { # explicity request to use these global variables global $script_name, $databasename, $host, $user, $password; # connect to database $link = mysql_connect($host, $user, $password) or die("Connection failed: " . mysql_error()); # select our table mysql_select_db($databasename) or die("Database selection failed [$db_name]: " . mysql_error()); # send a query $sql = "SELECT * FROM college.classes ORDER BY class_id"; $result = mysql_query($sql) or die("Query failed: " . mysql_error()); echo "<FORM METHOD=POST ACTION=\"$script_name\">\n"; echo "<TABLE BORDER=1>\n"; # print the class selection table $table_row = "<TR>"; $table_row .= "<TH> </TH>"; $table_row .= "<TH>Class Name</TH>"; $table_row .= "<TH>Class Start Date</TH>"; $table_row .= "<TH>Credits</TH>"; $table_row .= "</TR>"; echo "$table_row\n"; while ($row = mysql_fetch_array($result)) { $table_row = "<TR>"; $table_row .= "<TD><INPUT TYPE=RADIO NAME=\"class\""; $table_row .= " VALUE=\"$row[class_id]\"></TD>"; $table_row .= "<TD>$row[name]</TD>"; $table_row .= "<TD>$row[start_date]</TD>"; $table_row .= "<TD>$row[credits]</TD>"; $table_row .= "<TR>"; echo "$table_row\n"; } echo "</TABLE>\n"; echo "<INPUT TYPE=SUBMIT NAME=\"button\" VALUE=\"Submit Result\">\n"; echo "<INPUT TYPE=SUBMIT NAME=\"button\" VALUE=\"View Result\">\n"; echo "</FORM>\n"; mysql_free_result($result); mysql_close($link); } function view_result() { # explicity request to use these global variables global $script_name, $databasename, $host, $user, $password; # connect to database $link = mysql_connect($host, $user, $password) or die("Connection failed: " . mysql_error()); # select our table mysql_select_db($databasename) or die("Database selection failed [$db_name]: " . mysql_error()); # send a query $sql = "SELECT student_id,class_id"; $sql .= "FROM college.student_in_class"; $sql .= "ORDER BY class_id"; $result = mysql_query($sql) or die("Query failed: " . mysql_error()); echo "<H2>Student in Class</H2>\n"; echo "<TABLE BORDER=1>\n"; # print the class selection table $table_row = "<TR>"; $table_row .= "<TH>Students ID</TH>"; $table_row .= "<TH>Class ID</TH>"; $table_row .= "</TR>"; echo "$table_row\n"; while ($row = mysql_fetch_array($result)) { $table_row = "<TR>"; $table_row .= "<TD>$row[student_id]</TD>"; $table_row .= "<TD>$row[class_id]</TD>"; $table_row .= "<TR>"; echo "$table_row\n"; } echo "</TABLE>\n"; echo "<FORM METHOD=POST ACTION=\"$script_name\">\n"; echo "<INPUT TYPE=SUBMIT NAME=\"button\" VALUE=\"Back to Student Page\">\n"; echo "</FORM>\n"; mysql_free_result($result); mysql_close($link); } function save_result($student, $class) { # explicity request to use these global variables global $script_name, $databasename, $host, $user, $password; # connect to database $link = mysql_connect($host, $user, $password) or die("Connection failed: " . mysql_error()); # select our table mysql_select_db($databasename) or die("Database selection failed [$db_name]: " . mysql_error()); # send a query $sql = "INSERT INTO college.student_in_class"; $sql .= "SET student_id='$student',class_id='$class'"; mysql_query($sql) or die("Query failed: " . mysql_error()); mysql_close($link); return mysql_insert_id(); } ?> <HTML> <HEAD><TITLE>Welcome to Class Selection Page</TITLE></HEAD> <BODY> <?php # main routine switch ($button) { case 'Submit Result': save_result($student, $class); select_student(); select_class(); break; case 'View Result': view_result(); break; default: select_student(); select_class(); } ?> </BODY></HTML> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php