View Full Version : whats wrong with this query?

01-03-2006, 07:41 PM
$query = "INSERT INTO registeredcourses (Grade) VALUES (2) where StudentNo=$z AND CourseCode='c1' ";

Velox Letum
01-03-2006, 08:15 PM
We can't really help you with the limited amount of information you've given us. A table layout would be nice, as well as the output of:

$query = "INSERT INTO registeredcourses (Grade) VALUES (2) where StudentNo=$z AND CourseCode='c1' ";
mysql_query($query) or die(mysql_error());

which would give us a MySQL error to help debug your problem.

01-03-2006, 08:22 PM

01-03-2006, 08:23 PM
somethign like this?

$query = "INSERT INTO registeredcourses VALUES grade='2' where StudentNo='$z' AND CourseCode='c1' ";

although you will get an error if you need to fill in other fields

01-03-2006, 08:27 PM
so should i use UPDATE ??

01-03-2006, 08:29 PM
so should i use UPDATE ??

well your not specifying what you need to do.

Insert, if you want to insert a whole new record. From what it looks like if you want to add a bunch of grades to a students record, than you would need a seperate table for grades.

But if the student just has 1 grade, than you would use update.

message me if you don't want to talk about your program in public

01-03-2006, 08:35 PM
for example i want to ad garde A to coursecode c1 to student 058686
students can have more than 1 course.so maybe i need add 2 grades for one student.you say this table dont work for this proceses?

01-03-2006, 08:59 PM
ok, well here is your update query:

$update = mysql_query("UPDATE registeredcourses SET grade='2' WHERE StudentNo='$z' AND CourseCode='c1'") or die (mysql_error());

I still am thinking that your structure is off, but whatever works for you is fine :D