Welcome! Log In Create A New Profile

Advanced

editing course

Posted by Johnny - 72985186 
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
avatar editing course
May 06, 2011 10:29AM
My course table is updating fine, but added some code to update the cname in the student table aswell. Queries seem to be fine and not getting any errors up until I submit the newly entered cname. Then I get a " Unknown column ' new course name' in 'where clause". What does this error mean?

Here is my code:
Language: PHP
if (!isset($_POST[';submit';])) { $q = "SELECT * FROM course WHERE cid = $_GET[cid]"; $result = mysql_query($q); $person = mysql_fetch_array($result);     $cname = mysql_real_escape_string($_GET[';cname';]); $q2 = "SELECT * FROM student WHERE cname = ';$cname';"; $result2 = mysql_query($q2); $person2 = mysql_fetch_array($result2);     }   ?>   <h1> You are editing a course </h1> <form action="<?php echo $_SERVER[';PHP_SELF';]; ?>" method="post">   <p>Course Name:</p> <INPUT TYPE = "text" name = "cname"value= "<?php echo $person[';cname';]; ?>" /> <br>       <input type= "hidden" name="cid" value="<?php echo $_GET[';cid';]; ?>" />   <INPUT TYPE = "submit" name="submit" VALUE = "Update"/> </form>   <?php   if(isset($_POST[';submit';])) {   $u = "UPDATE course SET `cname` = ';$_POST[cname]'; WHERE cid = $_POST[cid]"; mysql_query($u) or die(mysql_error());   $u2 = "UPDATE student SET `cname` = ';$_POST[cname]'; WHERE cname = $_POST[cname]"; mysql_query($u2) or die(mysql_error());     echo "course has been modified!";           } ?>
Re: editing course
May 06, 2011 09:58PM
Your code for updating 'cname' in the 'course' table seems to be working well... From my understanding the 'student' table doesn't have the 'cname' field, you might be confusing it with the 'sname' field for surnames, please look at it well
avatar Re: editing course
May 07, 2011 03:00PM
Wow... this clears up alot of confusion. I fail so bad haha for some reason I had a cname field in my student table. So with that being said I did my whole thing wrong cause I used that field for various things. This is a bit of a hassle, especially so close to the deadline. So the course_student table fields sno and cid we link in sql code to the other table fields so they update along with those fields?
Re: editing course
May 07, 2011 09:45PM
I'm glad you saw that... You only need to update cname in the course table, the course_student doesn't have to be updated nor be touched when doing this one because the cid in the course table doesn't change. You only gonna need it when removing a course, if you want to remove students associated with the course you are removing.
avatar Re: editing course
May 08, 2011 03:03PM
Thanks alot, saved me from making alot of mistakes here haha. So how do I go about linking the sno field from student and the sno from course_student?
avatar Re: editing course
May 08, 2011 06:31PM
perhaps you can use a join or a while loop
Re: editing course
May 10, 2011 01:21PM
This is answered in details in the Assignment 2 topic, check it out
Sorry, only registered users may post in this forum.

Click here to login