php中每条记录中的动态文本框

时间:2016-07-10 15:30:26

标签: php html

我想从droptown选择Class时从数据库中获取学生详细信息。每个记录都应该有一个动态文本框,用于分配卷号。为此,我使用的是Ajax,它工作正常。 PHP代码和HTML代码如下所示

 <?php
 $cls=$_GET['hhcls'];
 $r11=$_GET['srno'];
 if($r11=='')
 {
   $r11=1;
 }
 $conn=mysql_connect("localhost","root","");
 mysql_select_db("school",$conn);
 $query=mysql_query("select * from stu_class where class='$cls'",$conn);
 echo "<table cellpadding=5 cellspacing=1 width='100%'>";                               
 echo "<tr align=center class='menu' bgcolor=#F5F5F5><td>Registration No.                  </td><td>Student Name</td><td>Roll No.</td></tr>";                   
while($data=mysql_fetch_row($query))
{
echo "<tr>";
echo "<td align=center>$data[0]</td>";
echo "<td align=center>$data[1]</td>";
echo "<td align=center><input type='text' name=$data[0] id=$data[0] value=$r11></td>";
echo "</tr>";
$r11=$r11+1;
}
echo "</table>";
?>

HTML代码如下所示

  <!DOCTYPE html>
  <!--[if lt IE 7]> <html class="lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
  <!--[if IE 7]> <html class="lt-ie9 lt-ie8" lang="en"> <![endif]-->
  <!--[if IE 8]> <html class="lt-ie9" lang="en"> <![endif]-->
  <!--[if gt IE 8]><!--> <html lang="en"> <!--<![endif]-->
  <?php
   session_start();
   if(($_SESSION["adm"])=='0') 
   {
    echo "<script type='text/javascript'>alert('You are not Authenticate for  this Module');</script>"; 
    print('<script>window.location.href="main.php"</script>');
   }
   else
   {
     $sn=$_SESSION["sname"];
   }

   ?>
   <head>
   <meta charset="utf-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
   <title>OSMS-Staff Hirement</title>
   <link rel="stylesheet" href="css/styles.css">
   <link rel="STYLESHEET" type="text/css" href="style/fg_membersite.css" />
   <link rel="STYLESHEET" type="text/css" href="style/pwdwidget.css" />
   <!--[if lt IE 9]><script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
   </head>
   <body>
   <?php
   $host="localhost";
    $dbusername="root";
        $dbpassword="";
        $dbname="school";
        $conn=mysql_connect($host,$dbusername,$dbpassword) or die(mysql_error());
        mysql_select_db($dbname) or die(mysql_error());
   if(isset($_POST['submit']))
   {

    $cls=$_POST['hhcls'];


{

    {

        {
            $query=mysql_query("select * from stu_class where class='$cls'",$conn);
            while($data=mysql_fetch_array($query))
            {
                //$r1=$data[0];
                //$r=$_POST[$r1];
                //echo $r;
                $query1="update stu_class set rollno='" . $_POST[$data[0]] . "' where ad_no='" . $_POST[$data[0]];
                $sql_query1=mysql_query($query1) or die(mysql_error());
                if($sql_query1)
                {
                    echo "<script type='text/javascript'>alert('Students Details Updated Successfully');</script>"; 
                }
                else
                {
                    echo "<script type='text/javascript'>alert('Updation Failed');</script>"; 
                }


            }   


        }

    }
}

 }
  ?>
  <script type="text/javascript">
  function gen()
 {
    var e = document.getElementById("category_gen");
    var gene = e.options[e.selectedIndex].value;
    document.getElementById("hgen").value=gene;

 }
 </script>
 <script type="text/javascript">
 function bgg() 
 {
     var e = document.getElementById("category_bld");
     var gen = e.options[e.selectedIndex].value;
     document.getElementById("hbg").value=gen;
 }
 </script>
 <script type="text/javascript">
 function natt()
 {
    var e = document.getElementById("category_nat");
    var gen = e.options[e.selectedIndex].value;
    document.getElementById("hnat").value=gen;
 }
 </script>
 <script type="text/javascript">
 function rell()
{
   var e = document.getElementById("category_rel");
   var gen = e.options[e.selectedIndex].value;
   document.getElementById("hreli").value=gen;
}
</script>
<script type="text/javascript">
function commm()
{
   var e = document.getElementById("category_comm");
   var gen = e.options[e.selectedIndex].value;
   document.getElementById("hcomm").value=gen;
}
</script>
<script type="text/javascript">
function clss()
{
   var e = document.getElementById("category_cls");
   var gen = e.options[e.selectedIndex].value;
    document.getElementById("hcls").value=gen;
   var gen1=e.options[e.selectedIndex].text;
  document.getElementById("hhcls").value=gen1;
  post1();
}
</script>
<script type="text/javascript">
 function post1()
 {
   var d=document.getElementById("hhcls").value;
   var d1=document.getElementById("srno").value;
   var xhttp = new XMLHttpRequest();
   xhttp.onreadystatechange = function() {
  if (xhttp.readyState == 4 && xhttp.status == 200) {
   document.getElementById("responsecontainer").innerHTML =        xhttp.responseText;
   }
 };
  xhttp.open("POST", "rollassign.php?hhcls="+d+"&srno="+d1, true);
  xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

 xhttp.send();
  }
  </script>
  <?php include('/menu.php');?>
  <table width="100%" border="0" cellspacing="0" cellpadding="0">



   <tr>
    <td><table width="100%" border="0" style="background:#FFFFFF;" cellspacing="0" cellpadding="0">
      <tr>
        <td align="center"><table width="100%"  border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF">

          <tr>
            <!-- Start : Site Menu -->

            <!-- End : Site Menu -->

            <!-- Start : Table Of Contents -->
            <td valign="top" class="bodytext">

            <table cellpadding="0" cellspacing="0" border="0" width="99%" align="left">
                <tr>

                <td>
                <table cellspacing="2" border="0" width="100%"  cellpadding="5" style="border:1px solid #E5E5E5; background:#F8F8F8;">
                <tr>
                <td width="20%">
                <form method='POST' action="<?php echo $_SERVER['PHP_SELF']; ?>">
                </td>
                <input name="hnat" type="hidden" id="hnat" value="0" />
        <input name="hreli" type="hidden" id="hreli" value="0" />
        <input name="hcomm" type="hidden" id="hcomm" value="0" />
        <input name="hcls" type="hidden" id="hcls" value="0" />
        <input name="hhcls" type="hidden" id="hhcls" value="0" />
                <td>Select Category</td>
                <td><select name="category_cls" id="category_cls" class="frmselect" style="width:220px;" onChange="clss();">
                                                    <option value="0">-- Select Class--</option>
                                                    <option value="1">LKG</option>
                                                    <option value="2">UKG</option>
                                                    <option value="3">I</option>
                                                    <option value="4">II</option>
                                                    <option value="5">III</option>
                                                    <option value="6">IV</option>
                                                    <option value="7">V</option>
                                                    <option value="8">VI</option>
                                                    <option value="9">VII</option>
                                                    <option value="10">VIII</option>

                                                    </select>
                </td>
                <td >Starting Roll No.<input type="text" id="srno" onBlur="post1();" name="srno" value=""></td>
                </tr>

                 </table>
              </td>
                </tr>
              <tr>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td><img src="images/spacer.gif" width="1" height="5"></td>
                </tr>
                <tr><td align="center" valign="top">

                <div id="responsecontainer">
                </div>

                </td></tr>
                <tr>
                    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="75%"></td>
                        <td width="25%" align="right">


                                                                        <INPUT  class="btnform" type="submit" id="submit" name="submit" value="SAVE">


                                            <input type="hidden" name="txtHid" value="<?php echo $_REQUEST['product_id'];?>"></td>
                        </tr>
                      </table></td>
                    </tr>
                    </form>
                <tr>
                  <td>&nbsp;</td>
                </tr>
              </table>


            </td>
            <!-- Start : Table Of Contents -->
            </tr>
  </table></td>
      </tr>
      </table></td>
  </tr>
  <!-- Footer -->

  <!-- Footer -->
   </table>

 </body>
 </html>

我面临的问题是在分配动态文本框后更新数据库时,它会抛出php错误undefined Offset:1 请帮我。 我需要指导 1.想要在选择下拉列表时为每条记录创建动态文本框 2.我想在数据库中的动态文本框中发布数据

谢谢

0 个答案:

没有答案