Welcome! Log In Create A New Profile

Advanced

course_student table

Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
course_student table
November 05, 2010 10:58AM
NEED HELP PLEASE as time is running out. Managed to get something into course_student but now I keep getting values 0 inserted as sno and cid in course_student table. In student and course it gets inserted correctly as new sno and cid each time I add a student or a course.

Code for commitstudent:
Language: PHP
<?php //other code   //gives me the cid of the course the student selected $cname = $_POST[';cname';]; $cid = $_POST[';cid';];   //insert the new student into database switch ($_GET[';action';]) { case "add": $sql = "INSERT INTO student (sname, init, fname, title, msname, dob, sex, lang, idno, telh, telw, cel, fax, email, address) VALUES (';" . $_POST[';sname';] . "';, ';" . $_POST[';init';] . "';, ';" . $_POST[';fname';] . "';, ';" . $_POST[';title';] . "';, ';" . $_POST[';msname';] . "';, ';" . $_POST[';dob';] . "';, ';" . $_POST[';sex';] . "';, ';" . $_POST[';lang';] . "';, ';" . $_POST[';idno';] . "';, ';" . $_POST[';telh';] . "';, ';" . $_POST[';telw';] . "';, ';" . $_POST[';cel';] . "';, ';" . $_POST[';fax';] . "';, ';" . $_POST[';email';] . "';, ';" . $_POST[';address';] . "';)"; break; }   if (isset($sql) && !empty($sql)) { echo "<!--" . $sql . "-->"; $result = mysql_query($sql) or die("Invalid query: " . mysql_error());   //get the new students sno $query = "SELECT max(sno) FROM student "; $result = mysql_query($query) or die(mysql_error());   //insert sno and cid into student_course table $sql = "INSERT INTO course_student (sno, cid, year) VALUES (';" . $_POST[';sno';] . "';, ';" . $_POST[';cid';] . "';, ';2010';)";   $result = mysql_query($sql) or die(mysql_error());   ?> <p align="center"> You have successfully registered as a new student. <br><a href="student_man.php">OK</a> </p>   <?php } ?>

My student_reg code:
Language: PHP
//other code <form action="commitstudent.php?action=add&type=student" method="post">   <table border="0" align="center" cellspacing="10" cellpadding="3"> <tr> <td width="50%">Surname</td> <td width="50%"><input type="text" name="sname"></td> </tr> <tr> <td>Initials</td> <td><input type="text" name="init"></td> </tr> <tr> <td>Full First Name</td> <td><input type="text" name="fname"></td> </tr> <tr> <td>Title</td> <td><input type="text" name="title"></td> </tr> <tr> <td>Maiden or previous surname</td> <td><input type="text" name="msname"></td> </tr> <tr> <td>Date of Birth</td> <td><input type="text" name="dob"></td> </tr> <tr> <td>Gender</td> <td><input type="text" name="sex"></td> </tr> <tr> <td>Language for Correspondence</td> <td><input type="text" name="lang"></td> </tr> <tr> <td>Identity Number</td> <td><input type="text" name="idno"></td> </tr> <tr> <td>Home Telephone Code + Number</td> <td><input type="text" name="telh"></td> </tr> <tr> <td>Work Telephone Code + Number</td> <td><input type="text" name="telw"></td> </tr> <tr> <td>Cellphone Number</td> <td><input type="text" name="cel"></td> </tr> <tr> <td>Fax Code + Number</td> <td><input type="text" name="fax"></td> </tr> <tr> <td>E-mail Address</td> <td><input type="text" name="email"></td> </tr> <tr> <td>Postal Address of Student</td> <td><input type="text" name="address"></td> </tr> <tr> <td>Choose a course:</td> <td> <select name="cname" style="width:150px"> <?php $sql = "SELECT cname " . "FROM course ORDER BY cid"; $result = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { echo ';<option value="'; . $row[';cid';] . ';">'; . $row[';cname';] . ';</option>'; . "\r\n"; } ?> </select> </td> </tr> <tr> <td colspan="2" align="right"> <input type="submit" name="SUBMIT" value="Register"></td> </tr>   //other code
Re: course_student table
November 05, 2010 11:44AM
your problem is that you are selecting the max sno but you are trying to use post['sno'] in the second insert query. post is only used if you have posted data from a form which in this case you havent.

i see you have a query getting the max sno that you have inserted so now put that sno into a variable and instead of using post['sno'] use that new variable.

Make sense?
Re: course_student table
November 05, 2010 12:22PM
Thanks for responding so fast! still trying ...
Re: course_student table
November 05, 2010 01:25PM
I agree on the sno as per rogerdurbs

on cid - Looks like this is a common mistake - I made it too - you've got your cid and cname the wrong way around on your student_reg page. Check the last bit of the other post - Final Prac - delete.php & student_course table.

Don't panic! cool smiley

Keep us posted
Re: course_student table
November 05, 2010 01:29PM
One further piece of advice....

Solve one problem at a time!
Sorry, only registered users may post in this forum.

Click here to login