hello guys i have a problem and i beg for help, i'm doing a student IS
i have a result table which store students results it is named capture 3
i have developed html form accept user who add marks for a particular student
these are the hmtl code

<?php error_reporting(E_ALL ^ E_NOTICE); ?>
<html>
<body>
<div>
<div>
<form action="connmarks.php" method="post">
    <table>
    <tr><td colspan="6">&nbsp;</td></tr>
    <tr>
    <td width="9%">Student Code<?php echo $mstudentcode;?></td>
    <td width="17%"><input name="student_code" type="text" size="30" value="<?php echo $studentcode;?>" /></td>
    <td width="10%">Subject Code<?php echo $msubjectcode;?></td>
    <td width="18%"><input name="subject_code" type="text" size="30"  value="<?php echo $subjectcode;?>"/></td>
    <td width="12%">Subject Name<?php echo $msubjectname;?></td>
    <td width="34%"><input name="subject_name" type="text" size="30" value="<?php echo $subjectname;?>"/></td>
    </tr>
    <tr><td colspan="6">&nbsp;</td></tr>
    <tr>
    <td>Marks<?php echo $mmarks;?></td>
    <td><input name="marks" type="text" size="30" value="<?php echo $marks;?>"/></td>
      <td>&nbsp;</td>
      <td>&nbsp;
      </td>
    </tr>
     <tr><td colspan="4">&nbsp;</td></tr>
      <tr><td colspan="6">&nbsp;</td></tr>
     <tr>
    <td>&nbsp;</td><td colspan="6"><input type="submit" name="save" value="Add Marks" /></td>
     </tr>
     <tr><td colspan="6"><?php echo $sms1.$sms.$sms2;?></td></tr>
    </table>
    </form>
    </div>
    <div id="footer">Copyright <?php echo date("Y", time()); ?></div>
</div>
</body>
</html>

then i wrote php script which process information which comes from that html form
here are the php script

<?php error_reporting(E_ALL ^ E_NOTICE); ?>
<?php
session_start();
if(isset($_POST['save']))
{
//  validating student code
    if(empty($_POST['student_code']))
    {
        $mstudentcode='<font color="red"><b>**</b></font>';
    }
    else
    {
        $student_code=$_POST['student_code'];
    }
// No validation for subject code
    if(empty($_POST['subject_code']))
    {
        $msubjectcode='<font color="red"><b>**</b></font>';
    }
    else
    {
        $subject_code=$_POST['subject_code'];
    }
// validating subject name
    if(empty($_POST['subject_name']))
    {
        $msubjectname='<font color="red"><b>**</b></font>';
    }
    else
    {
        $subject_name=$_POST['subject_name'];
    }
// validating marks
    if(empty($_POST['marks']))
    {
        $mmarks='<font color="red"><b>**</b></font>';
    }
    else
    {
        $marks=$_POST['marks'];
    }
// checking if there is any error message, if no error proceed, if there is error, display the error
//  Then exit the script and redirect at the same page
    if($mstudentcode||$msubjectcode||$msubjectname||$mmarks||$sms)
    {
        $sms1='<font color="red"><b>Error found,please check **</b></font><br/>';
        include 'addmarks.php';
        exit;
    }
// if there is no error include connection file
    if($student_code&&$subject_code&&$subject_name&&$marks)
    {
//      include 'mysqli_connect.php';
      require_once ('../../mysqli_connect.php');
        $addmarks= "insert into result(student_code,subject_code,subject_name,marks) values ('".$student_code."','".$subject_code."','".$subject_name."','".$marks."')";
        $k = mysqli_query($dbc, $addmarks);
        if ($k)
        {
       $sms1='<font color="green"><b>Student Marks Submitted Successfully</b></font><br/>';
            include 'addmarks.php';
                        exit;
        }
        else
        {
            $sms1='<font color="red"><b>Failed To Add Student Marks</b></font><br/>';
            include 'addmarks.php';
                        exit;
        }
    }
    }
?>

every thing is added successfully in the result table but the appearance of the result table in the phpmyadmin is quite different to what i expected once i added the the marks, student_code, subject_code and subject_name
I have six subject, what i expected is every student should have all his/her marks in only one column. what i get now is this

 student_code   subject_code       subject_name             marks
    01           01                  Kiswahili                  50
    01           02                  English                    50
    01           03                  Hisabati                   40
    01           04                  Huji                       44
    01           05                  Stadi Za Kazi              36
    01           06                  Sayansi                    42

but i want to get this in phpmyadmin

You can see here every student all of his/her marks are in one column, unlike above

STUDENT_CODE    KISWAHILI   ENGLISH HISABATI    HUJI    STADI ZA KAZI   SAYANSI
1                   50          50      40       44          36           42
2                   48          46      36       46          44           42 
3                   48          40      44       42          45           38
4                   50          50      36       44          40           38
5                   42          50      40       42          38           46

here is my result table structure

    1   student_code    varchar(250)                

    2   subject_code    varchar(250)            

    3   subject_name    varchar(250)                

    4   marks   int(10) 

here is my subject table with subject name and subject code already inserted

subject_code    subject_name
1                Kiswahili
2                English
3                Hisabati
4                Huji
5                Stadi Za Kazi
6                Sayansi

Also is there a way where by i can add marks for all six subject at once, instead of adding marks for one subject at a time and then submit and then take marks for another subject and then add, until all the marks for six subjects are complete and then take another student then do the same thing, i'm asking this, foristance you have 400 students and each student take all the six subjects, will it be possible to use a loop.

This shows each subject_name in separate rows with subject_name as the table field.

 student_code   subject_code       subject_name             marks
    01           01                  Kiswahili                  50
    01           02                  English                    50
    01           03                  Hisabati                   40
    01           04                  Huji                       44
    01           05                  Stadi Za Kazi              36
    01           06                  Sayansi                    42

This shows each subject as a separate table field.

STUDENT_CODE    KISWAHILI   ENGLISH HISABATI    HUJI    STADI ZA KAZI   SAYANSI
1                   50          50      40       44          36           42
2                   48          46      36       46          44           42 
3                   48          40      44       42          45           38
4                   50          50      36       44          40           38
5                   42          50      40       42          38           46

They are completely different and will work differently. The first example creates different rows for the same user with each row being the score that goes with that subject. While the second example puts the score for each subject per user on the same row.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.