duanjuan3931 2017-04-05 07:12
浏览 51

如何使用PHP为html表单字段提供自动编号

***hi to all **i need to give auto numbering in the form for different users.If one user login and insert the data ,want to get the filed number as 1 and press next button and redirect to the form filling the another data number be 2,like that..

if second user login and filling the form they need to get the form number as 1 only as per the login id and date.

my html table

<html>
         <head>
             <style>
                 .data{ 
                 background : #e0e0a0;  
                 padding:5px;
                 align:center;
                 height:200px;
                 width:500px;
                 float:left;
                 margin-right:200px;
                 margin-left:400px;
                 border:1px  #000000;
                 border-radius: 0px ;}

               </style>
          </head>
          <script>
        var i = 1;
        function buttonClick() {
            i++;
            document.getElementById('inc').value = i;
        }
    </script>
             <body> 
             <?php
             if(isset($_SESSION['useremail']))
             {
                 ?>
                 <div class="data">
                     <form name="f1" method="post" action="material_action.php">
                         <table border="0" width="500" align="center" class="demo-table">
                             <tr>
                                 <th align=center colspan=2><h1>Materials</h1></th>
                             </tr>

                             <tr>
                             </tr>
                              <tr>
                                 <td><b>Code    :</b></td><td><input type=number name="code"class="counter"id="inc" value="1" required autofocus placeholder="slno:" ></td>
                             </tr>
                             <tr>
                                  <td><b>Materials:</b></td><td><input type=text name="material"  required autofocus placeholder="16mmply"></td>
                             </tr>
                             <tr>
                             </tr>
                             <tr>
                                 <td><b>shade:</b.</td><td><input type=text name="shade" required autofocus placeholder="bsl/osl" ></td>
                             </tr>
                             <tr>
                                 <td><b>Grains:</b.</td><td><input type="checkbox" name="grains" value="grains"> grains<br></td>
                             </tr>
                             <tr>
                             </tr>
                             <tr>
                               <tr><td>
                               <td><td><input type=submit value="NEXT"class="increment-btn"onclick="buttonClick();" name='button'>
                               <input type=submit value="VIEW" name='button'>
                                 <input type="submit" align=center name="submit" value="OK" class="btn register"><br/></td></tr>
                               </tr>

                                </form>
                       </table>
              </div>
             <?php
             }
             else
             {
                 header("location:login1.php");
             }
             ?>
           </body>

           </html>

> php code

     <?php
           session_start();  
    $counter=1;    

             if(isset($_POST)& !empty($_POST))   
     {
         $counter++;
         $sql="select custcode from users where useremail= '". $_SESSION['useremail'] ."'";
                   require'connect.php';
                    $result = mysqli_query($con,$sql);
                    $code=mysqli_fetch_array($result);
                    $company=$code['custcode'];
                    $count=mysqli_num_rows($result);
                    if($count>0)
                   {
                     $cust=$company.date(" dmy");
                    $_SESSION['customercode']=$cust;
                   }
        $code=$_POST['code'];           
        $material=$_POST['material'];
        $shade=$_POST['shade'];
         $cust=$_SESSION['customercode'];
        $grains=$_POST['grains'];



           if($code=='')
            {
                header('location:./reg.php?error=Generate the code for materials!!!');
                exit();
            }
            if (isset($_POST['grains']) && ($_POST['grains'] == "grains")) {
     $grains .= "grains";
    } else {
     $grains .= "--";
    }


               $q="insert into material(code,material,shade,grains,customercode )values('$code','$material','$shade','$grains','$cust')";

             require'connect.php';
             $result=mysqli_query($con,$q);

         if($_REQUEST['button']=="NEXT")
           {
                $_SESSION['Quantity']=$qnt;

            header("location:material.php");
           }
         else
          {
           $errcode=mysqli_errno($con);
          }
        if($_REQUEST['submit']=="OK") 
         {
        header("location:data.php");
         }
       else
       {
        echo"try again";
       }    

    }


    ?>
 <?php
       session_start();  
$counter=1;    

         if(isset($_POST)& !empty($_POST))   
 {
     $counter++;
     $sql="select custcode from users where useremail= '". $_SESSION['useremail'] ."'";
               require'connect.php';
                $result = mysqli_query($con,$sql);
                $code=mysqli_fetch_array($result);
                $company=$code['custcode'];
                $count=mysqli_num_rows($result);
                if($count>0)
               {
                 $cust=$company.date(" dmy");
                $_SESSION['customercode']=$cust;
               }
    $code=$_POST['code'];           
    $material=$_POST['material'];
    $shade=$_POST['shade'];
     $cust=$_SESSION['customercode'];
    $grains=$_POST['grains'];



       if($code=='')
        {
            header('location:./reg.php?error=Generate the code for materials!!!');
            exit();
        }
        if (isset($_POST['grains']) && ($_POST['grains'] == "grains")) {
 $grains .= "grains";
} else {
 $grains .= "--";
}


           $q="insert into material(code,material,shade,grains,customercode )values('$code','$material','$shade','$grains','$cust')";

         require'connect.php';
         $result=mysqli_query($con,$q);

     if($_REQUEST['button']=="NEXT")
       {
            $_SESSION['Quantity']=$qnt;

        header("location:material.php");
       }
     else
      {
       $errcode=mysqli_errno($con);
      }
    if($_REQUEST['submit']=="OK") 
     {
    header("location:data.php");
     }
   else
   {
    echo"try again";
   }    

}


?>
  • 写回答

1条回答 默认 最新

  • dongliao4353 2017-04-05 07:16
    关注

    I dont quite understand your question but if im right. What you need is setting a variable

    $variable = 0;
    

    And when something happens then just do:

    $variable++;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录