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><?phpif(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!";}?>
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
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?
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.