Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
I am a student doing a mini project Using PHP. In my administrator page I have a bug. i.e, First it Prompts for.

-->Hall ticket No
-->Semester of the particular student.
Whenever admin enters these details and clicks firstsubmit button, it display the marks of particular student in textboxes.
If the marks are not available it displays empty text boxes, those allows the admin to insert the marks for that particular student.
After entering marks whenever he clicks second submit button, the marks have to be inserted in the database table.
NOTE: Marks and second submit buttons appear only when admin clicks first submit button by enetring Hallticketno and semester.
Bug is when I fill the text boxes with subjectwise marks and click second submit button it is inserting '0's for all the subjects in the table Instead of entered marks in the textboxes.
And here is my code:
XML
<html>
         <body bgcolor="#abcdfg">
            <center><h2>WELCOME TO ADMINISTRATOR</H2>
                   <form name="admin" action="admin1.php" method="POST">
                  Hall Ticket No.:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="text" name="rno" value=""/>
                      <br>
                      <br>
                       Enter The Semister:
                    <input type="text" name="sem" value=""/>
                        <br>
                             <br>
                       <input type="submit" name="submit1" value="Load the marks">
                          </form>


                     <?php
                  if(isset($_POST['submit1']))
                  {
                  $id=$_POST['rno'];
                  $semester=$_POST['sem'];
                  $link = mysql_connect('127.0.0.1', 'root', '');


                           if (!$link) {
                                  die('Could not connect: ' . mysql_error());
                                                 }


                $db_selected = mysql_select_db('etudient', $link);
                        if (!$db_selected) {
                               die ('Can\'t use etudient : ' . mysql_error());
                               }
  $sql='SELECT *
                               FROM `2-1`
                               WHERE id='."'".$id."'";
                               $result=mysql_query($sql);

                             if (mysql_num_rows($result)==0)
                               {
                               echo 'marks were not entered for '.$id.' in '.$semester. ' semester'.'<br>';
                                    $empty='SELECT subname
                               FROM `2-1subjects`';


                               $eresult=mysql_query($empty);
                               if(!$eresult)
                        {
                        die('invalid Query:'.mysql_error());
                        }
                        Print "<table border=0 cellpadding=10>";
                        //Print "<th>SUBJECT CODE</th>";
                        Print "<th>SUBJECT NAME</th>";
                        Print "<th>MARKS</th>";
                        while($cow = mysql_fetch_array($eresult))
                                {
                                      Print "<tr>";
                                //Print "<td>".$row['subcode'] . "</td> ";
                                print "<td>".$cow['subname'] . "</td> ";
                                //Print "<td>".$row['marks'] . "</td> ";
                                ?>
                                <form method="POST">
                            <td> <input type="text" name="mark" style="text-align:center" value=""/></td>
                            </form>
                                <?php
                                Print "</tr>";
                                   }
                                  Print "</table>";
                                  ?>

                                   <input type="submit" name="submit2" value="Insert Marks"/>

                                   <?php
                                     if(isset($_POST['submit2']))
                                        {
                                          $insq='SELECT subcode
                                           FROM `2-1subjects`';
                                            if(!$insq)
                                          {
                                          die('invalid Query:'.mysql_error());
                                          }

                                          $insre=mysql_query($insq);
                                          while($subrow=mysql_fetch_array($insre))
                                          {
                                          $mr=$_POST['mark'];
                                          $inser='INSERT into `2-1`(id,subcode,marks)
                                          VALUES('."'".$id."'".','
                                                  ."'".$subrow['subcode']."'".','
                                                  ."'".$mr."'".')';
                                          $inseresult=mysql_query($inser);
                                          if(!$inseresult)
                                          {
                                          die('invalid Query:'.mysql_error());
                                          }
                                          }
                                            echo "successfully Inserted.";

                                        }
                                        else{
                                        echo 'not submitted.';
                                        }

                                }



                               else
                               {
                               echo 'Marks Details of  '.$id.'   in  '.$semester.'  semester'.'<br>';
                               $query='SELECT subname,marks
                               FROM `2-1subjects`
                               JOIN `2-1`
                               ON `2-1subjects`.subcode=`2-1`.subcode
                               WHERE id='."'".$id."'";

                               $sql=mysql_query($query);
                               if(!$sql)
                        {
                        die('invalid Query:'.mysql_error());
                        }
                        Print "<table border=0 cellpadding=10>";
                        //Print "<th>SUBJECT CODE</th>";
                        Print "<th>SUBJECT NAME</th>";
                        Print "<th>MARKS</th>";
                        while($row = mysql_fetch_array($sql))
                                {
                                      Print "<tr>";
                                //Print "<td>".$row['subcode'] . "</td> ";
                                print "<td>".$row['subname'] . "</td> ";
                                //Print "<td>".$row['marks'] . "</td> ";
                                ?>

                            <td> <input type="text" style="text-align:center" value="<?php echo $row['marks'] ?>" /></td>
                                <?php
                                Print "</tr>";
                                   }
                                  Print "</table>";
                                  print '<input type="submit" name="submit" value="Update Marks"/>';
                                  }


and the values are being inserted in reverse order into the table that means bottom to top rather than that of which I entered at the time of inserting in textboxes. please correct my code.
Thanks in advance.
Posted
Updated 13-Jan-13 16:09pm
v2

1 solution

Hello. as the code partially excerpted here, so it's not fully clear to me, but I submit a revised part of your code just considering my gesture.

XML
<html>
         <body bgcolor="#abcdfg">
            <center><h2>WELCOME TO ADMINISTRATOR</H2>
                   <form name="admin" action="admin1.php" method="POST">
                  Hall Ticket No.:
                    <input type="text" name="rno" value=""/>
                      <br>
                      <br>
                       Enter The Semister:
                    <input type="text" name="sem" value=""/>
                        <br>
                             <br>
                       <input type="submit" name="submit1" value="Load the marks">
                          </form>


                     <?php
                  if(isset($_POST['submit1']))
                  {
                  $id=$_POST['rno'];
                  $semester=$_POST['sem'];
                  $link = mysql_connect('127.0.0.1', 'root', '');


                           if (!$link) {
                                  die('Could not connect: ' . mysql_error());
                                                 }


                $db_selected = mysql_select_db('etudient', $link);
                        if (!$db_selected) {
                               die ('Can\'t use etudient : ' . mysql_error());
                               }
  $sql='SELECT *
                               FROM `2-1`
                               WHERE id='."'".$id."'";
                               $result=mysql_query($sql);

                             if (mysql_num_rows($result)==0)
                               {
                               echo 'marks were not entered for '.$id.' in '.$semester. ' semester'.'<br>';
                                    $empty='SELECT subname
                               FROM `2-1subjects`';


                               $eresult=mysql_query($empty);
                               if(!$eresult)
                        {
                        die('invalid Query:'.mysql_error());
                        }

                        ?>
                        <form method="POST">
                        <?
                        echo "<table border=0 cellpadding=10>";
                        //Print "<th>SUBJECT CODE</th>";
                        echo "<th>SUBJECT NAME</th>";
                        echo "<th>MARKS</th>";
                        while($cow = mysql_fetch_array($eresult))
                                {
                                      echo "<tr>";
                                //echo "<td>".$row['subcode'] . "</td> ";
                                echo "<td>".$cow['subname'] . "</td> ";
                                //echo "<td>".$row['marks'] . "</td> ";
                                ?>

                            <td> <input type="text" name="mark" style="text-align:center" value=""/></td>

                                <?php
                                echo "</tr>";
                                   }
                                  echo "</table>";
                                  ?>

                                   <input type="submit" name="submit2" value="Insert Marks"/>

                                   <?php
                                     if(isset($_POST['submit2']))
                                        {
                                          $insq='SELECT subcode
                                           FROM `2-1subjects`';
                                            if(!$insq)
                                          {
                                          die('invalid Query:'.mysql_error());
                                          }

                                          $insre=mysql_query($insq);
                                          while($subrow=mysql_fetch_array($insre))
                                          {
                                          $mr=$_POST['mark'];
                                          $inser='INSERT into `2-1`(id,subcode,marks)
                                          VALUES('."'".$id."'".','
                                                  ."'".$subrow['subcode']."'".','
                                                  ."'".$mr."'".')';
                                          $inseresult=mysql_query($inser);
                                          if(!$inseresult)
                                          {
                                          die('invalid Query:'.mysql_error());
                                          }
                                          }
                                            echo "successfully Inserted.";

                                        }
                                        else{
                                        echo 'not submitted.';
                                        }

                                }



                               else
                               {
                               echo 'Marks Details of  '.$id.'   in  '.$semester.'  semester'.'<br>';
                               $query='SELECT subname,marks
                               FROM `2-1subjects`
                               JOIN `2-1`
                               ON `2-1subjects`.subcode=`2-1`.subcode
                               WHERE id='."'".$id."'";

                               $sql=mysql_query($query);
                               if(!$sql)
                        {
                        die('invalid Query:'.mysql_error());
                        }
                        echo "<table border=0 cellpadding=10>";
                        //echo "<th>SUBJECT CODE</th>";
                        echo "<th>SUBJECT NAME</th>";
                        echo "<th>MARKS</th>";
                        while($row = mysql_fetch_array($sql))
                                {
                                      echo "<tr>";
                                //echo "<td>".$row['subcode'] . "</td> ";
                                echo "<td>".$row['subname'] . "</td> ";
                                //echo "<td>".$row['marks'] . "</td> ";
                                ?>

                            <td> <input type="text" style="text-align:center" value="<?php echo $row['marks'] ?>" /></td>
                                <?php
                                echo "</tr>";
                                   }
                                  echo "</table>";
                                  echo '<input type="submit" name="submit" value="Update Marks"/>';
                                  }?>
</form>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900