0

我有产品移交表格,用户需要输入产品序列号,范围为 1-100,数量值从下拉列表中手动选择,我希望用户只需输入序列号,数量字段将通过简单功能自动填充。例如,如果序列号没有从 1 到 100 的数量将是 100(方法=$from-$to+1=100)。请帮我使这个函数使用 PHP。

enter code here


  <body>
 <?php
 if(isset($_POST['submit']))
 {
$serial=$_POST['serial1']."-".$_POST['serial2'];
$addserial=$_POST['serial1']-$_POST['serial2'];
  $con=mysqli_connect("localhost","root","admin","myapps");
 // Check connection
  if (mysqli_connect_errno())
  {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$sql="INSERT INTO  `sales`(`ddate`, `agentid`, `rcvrname`, `deliverby`,
  `cardname`,     `caraserial`, `qty`, `posid`, `posserial`, `msidn`,
  `sim`, `note`)
VALUES(
'$_POST[ddate]',
'$_POST[agentid]',
 '$_POST[rname]',
  '$_POST[dlvrby]',
 '$_POST[card]',
'$serial',
'$_POST[qty]',
'$_POST[pos]',
'$_POST[posserial]',
 '$_POST[msidn]',
'$_POST[apnno]',
'$_POST[note]')";

   if (!mysqli_query($con,$sql))
  {
  die('Error: ' . mysqli_error($con));
    }
   header( "refresh:2;url=index.php" );

  $insert_status="Data Insert Successfull";
   //header("location: index.php");


   mysqli_close($con);
  }

  ?>


   <?php
   $con=mysqli_connect("localhost","root","admin","myapps");
  // Check connection
//print_r($con);
   if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }
$sql = "SELECT * FROM agent";
 $query = mysqli_query($con,$sql);
 while ( $results[] = mysqli_fetch_assoc( $query ) );
 array_pop ( $results );
// print_r($results);

 //array_pop ( $results );
  ?>
    <script language="JavaScript">
  <!--

  function enable_text(status)
 {
  status=!status;   
  document.myform.pos.disabled = status;
  }
  //-->
  </script>
 <div  style="padding-left:160px; font-weight: bold; font-size: 18px; color: #900;"  >
 <H1 align="center" class="header">PRODUCT HANDED OVER FORM</H1>
 <form id="myform" name="myform" method="post" onsubmit="return validateForm()">
  <table  width="650px" border="2" bordercolor="#FFCC00"
       align="center" cellpadding="3" cellspacing="3"><tr align="centre"
   style="border-spacing:">
                <td width="20%" align="left"><div align="left"> Dated:</div></td>
                <td width="20%"><input type="date" name="ddate"/></td>
                <td width="20%">Agent Id:</td>
                <td><select name="agentid" size="1"ID="ddlList">
                  <option value="">Select Agent</option>
                  <?php foreach ( $results as $option ) : ?>
                      <option value="<?php echo $option['Agentid']; ?>">
    <?php echo     $option['Agentid']; ?></option>
              <?php endforeach; ?></select></td></tr>

              <tr>
                <td>Reciver Name:</td>
                <td><input type="text" name="rname" /></td>
                <td>Deliver By:</td>
                <td><select name="dlvrby">
                  <option value="N">Select Name</option>
                  <option value="Y">Anisur Rahman</option>
                </select></td></tr>

              <tr>
                <td>Name of Card:</td>
                <td align="center"><select name="card" size="">
                  <option>Select Name</option>
                  <option>Meghna Bank Fastcash</option>
                  <option>FSIBL Fastcash</option>
                </select></td>
                <td>Serial No:</td>
                <td><input style="width:25%" type="text" name="serial1" /> - 
   <input  style="width:25%"  type="text" name="serial2" /> 
  <select  align="left"name="qty"> <option>Qty</option>
                  <option>25</option>
                  <option>50</option>
                  <option>75</option>
                  <option>100</option>
                  <option>125</option>
                  <option>150</option>
                  <option>175</option>
                  <option>200</option></select></td>

              </tr>
              <tr>
          <td>POS:<input type="checkbox" name=others  
    onclick="enable_text (this.checked)" ></td>
                <td><input type="text" name="pos" /></td>
                <td width="20%">POS Serial No:</td>
                <td><input type="text" name="posserial" /></td>
              </tr>
              <tr>
                <td>MSIDN  No:</td>
                <td><input type="text" name="msidn" /></td>
                <td>APN SIM:</td>
                <td><input type="text" name="apnno" /></td>
              </tr>
              <tr>
                <td>Note:</td>
                <td><textarea name="note" id="note"></textarea></td>
              </tr>


                <th bgcolor="#FFFF66"><input CausesValidation="true"
    name="submit"    size="170" type="submit" value="Submit" /></th>
  </tr>

   </table><div align="center" style="color:#900" >
  <?php echo isset($insert_status)?   $insert_status:''?> </div>



  </form>
 </div>
  </body>
4

1 回答 1

0

在您的 php 脚本中添加此函数。

function getSerialDiff($serialFrom,$serialTo){
      return $serialTo -($serialFrom+1);

}

在此处调用此函数代替此行

  $addserial=$_POST['serial1']-$_POST['serial2'];

作为

   $addserial=getSerialDiff(intval($_POST['serial1']),intval($_POST['serial2']));

并在 HTML 中查看此值,如下所示:

<input style="width:25%" type="text" name="qty" value = "<?php echo $addserial?>" />
于 2013-10-28T11:18:37.213 回答