在单个页面中有两个提交按钮的错误 [英] bugs with two submit buttons in a single page

查看:74
本文介绍了在单个页面中有两个提交按钮的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名学生在做一个使用PHP的迷你项目。在我的管理员页面中,我有一个错误。即,首先它会提示。



- >门票号码

- >特定学生的学期。 />
每当管理员输入这些详细信息并单击firstsubmit按钮时,它会在文本框中显示特定学生的标记。

如果标记不可用,则显示空文本框,这些文本框允许管理员使用为该特定学生插入标记。

每当他点击第二个提交按钮输入标记后,必须在数据库表中插入标记。

注意:标记和第二个提交按钮仅在管理员通过enetring Hallticketno和semester点击第一个提交按钮时出现。

错误是当我用主题标记填充文本框并单击第二个提交按钮时它插入''0'对于表格中的所有主题而不是在文本框中输入标记。

这是我的代码:

 <   html  >  
< body bgcolor = #abcdfg >
< center > < h2 > 欢迎使用管理员< / H2 >
< 表格 名称 = admi n action = admin1.php 方法 = POST >
Hall Ticket No.:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
< 输入 < span class =code-attribute> type = text 名称 = rno value = / >
< br >
< br >
输入Semister:
< span class =code-keyword>< input type = text name = sem value = / >
< br >
< br >
< span class =code-keyword>< 输入 type = 提交 名称 = submit1 value = 加载标记 >
< / form >


<? php

if(isset($ _ POST ['submit1'])) < span class =code-summarycomment>

< span class =code-summarycomment> {

< span class =code-summarycomment> $ id = $ _ POST [' rno'];

< span class =code-summarycomment> $ semester = $ _ POST [' sem'];

< span class =code-summarycomment> $ link = mysql_connect(' 127.0.0.1 ', 'root', '');





< span class =code-summarycomment> 如果 (!$ link) {

< span class =code-summarycomment> die('could connect: ' mysql_error());

< span class =code-summarycomment> }





< span class =code-summarycomment> $ db_selected = mysql_select_db(' etudient', $ link);

< span class =code-summarycomment> if (!$ db_selected) {

die ('不能 使用 etudient ' mysql_error());

< span class =code-summarycomment> }

$ sql =' SELECT *
FROM`2-1`
WHERE id ='
。'。$ id。 ';

$ result = mysql_query($ sql);



if (mysql_num_rows($ result) = = 0 )

< span class =code-summarycomment> {

echo 'marks 已输入 '。$ id。' '。$ semester。 < span class =code-summarycomment> ' 学期'。'< br > ';
$ empty ='SELECT子名
FROM`2-1subjects`';


$ eresult = mysql_query($ empty);
if(!$ eresult)
{
die('invalid Query:'。mysql_error());
}
打印< border = 0 cellpadding = 10 > ;
//打印< 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-ali gn: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.\"'\".','

< span class=\"code-summarycomment\">
.\"'\".$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.

解决方案

_POST['submit1']))

{


id=


_POST['rno'];


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.

解决方案

_POST['submit1'])) {


id=


_POST['rno'];


这篇关于在单个页面中有两个提交按钮的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆