Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: PHP
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:
<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 13-Jan-13 15:47pm
Edited 13-Jan-13 16:09pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
 
<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>
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 269
1 OriginalGriff 220
2 Peter Leow 205
3 _Amy 190
4 Andreas Gieriet 180
0 OriginalGriff 7,540
1 Sergey Alexandrovich Kryukov 6,412
2 Maciej Los 3,849
3 Peter Leow 3,653
4 CHill60 2,702


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 14 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100