-2
***嗨全部 **我需要在不同用戶的表單中提供自動編號。如果一個用戶登錄並插入數據,想要獲取該申請號作爲1個 按下按鈕並重定向到形式填充另一個數據 數目是2,像..如何給自動編號的HTML表單字段使用PHP
如果第二用戶的登錄和填充他們需要得到形式 數爲1的形式只根據登錄ID和日期。
我的HTML表格
<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代碼
<?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";
}
}
?>