0

It is the student_info table

 CREATE TABLE student_info
 (
              s_id varchar(50) NOT NULL,
              c_id varchar(50) ,
              sem_no varchar(50),
              quiz_mark varchar(50) ,
              att_mark varchar(50),
              total_mark varchar(50),
              exam_mark varchar(50),
              grade varchar(50),



);


insert into student_info values('0006','chem1115','1','15','9',' ','59 ',' '); 

insert into student_info values('0006','cse101','1','15','9',' ','70 ',' '); 

insert into student_info values('0006','cse111','1','15','9',' ','49 ',' ');

then i run these lines of code

   $sql2 = "SELECT c_id, quiz_mark, att_mark,exam_mark FROM student_info WHERE sem_no=$sem AND s_id = $s_id ";
   if($query_run = mysql_query($sql2)) {

       echo " <table border='1' >
                            <tr>
                            <th>Course-no.</th>
                            <th>quiz mark</th>
                            <th>att mark</th>
                            <th>exam mark</th>
                                                        <th>total mark</th>
                                                        <th>Grade</th>
                            </tr>";



         while ($row1 = mysql_fetch_array($query_run)){
             $c_nam = $row1['c_id'];
             $quiz_mark = $row1['quiz_mark'];
         $att_mark = $row1['att_mark'];
             $exam_mark=$row1['exam_mark'];  
             $total_mark= $att_mark+$exam_mark+$quiz_mark;
            $grade=grade($total_mark);
             $sql3="UPDATE student_info SET total_mark=$total_mark WHERE c_id=$c_nam";
             if(mysql_query($sql3)){


             }else {
                 echo mysql_error(); 
             } 


             echo "<tr>";
                     echo "<td>" .$c_nam. "</td>";
                     echo "<td>" .$quiz_mark. "</td>";
                     echo "<td>" .$att_mark. "</td>";
                      echo "<td>".$exam_mark."</td>";
                                          echo "<td>".$total_mark."</td>";
                                          echo "<td>".$grade."</td>";
                     echo "</tr>";






         }
         echo "</table> "; 

     }
     else{
      echo mysql_error();
              }

it is not working. I just can't upadte under a while loop !!

result:
Unknown column 'chem1115' in 'where clause'Unknown column 'cse101' in 'where clause'Unknown column 'cse111' in 'where clause'

chem1115 15 9 59 83 A+
cse101 15 9 70 94 A+
cse111 15 9 49 73 A-

the total_mark feild is not updated on the Database this is the problem !!

Edited by poshka

4
Contributors
4
Replies
20
Views
3 Years
Discussion Span
Last Post by jstfsklh211
0

The clue is in the error message. Unknown column 'chem1115' indicates that your sql statement is wrong. You have data where a column name should be.

And here is why:
...SET total_mark=$total_mark ...

PHP is interpreting total_mark as $total_mark because it thinks you have simply made a typo. If you checked your error logs you'd see the line where the PHP engine is recording that it made that assumption. And therefore you sql statement reads as "chem1115 = chem1115". Simply change your variable name from $total_mark to something that isn't so closely related to a column name.

0

Have you tried @hericles suggestion? What did it say?

I completely agree, this problem is caused by an SQL error, not PHP. Please tell us what you've done to rectify that so we can attempt to help you.

0

UPDATE student_info SET total_mark=$total_mark WHERE c_id=$c_nam

in any query string values in quotes are treated as text where as string values not in quotes are assumed to be sql (column names in this case)
in this case (col)total_mark = (col)[value from $totalmark]

just need to add single quotes around '$totalmark'

also you should really be using some form of sql injection prevention

Edited by jstfsklh211

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.