Click here to Skip to main content
15,878,871 members

bugs with two submit buttons in a single page

Member 9750618 asked:

Open original thread
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.
Tags: PHP

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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