保留从先前表单到新表单的输入


Retaining input from previous form to new form

我正在做我的学校项目,我有这个问题我的用户输入第一个报价单(insertquote.php)并提交后,它会把他带到插入报价流程.php这将告诉他订单已添加。然后,他可以选择将新项目添加到发票或返回。当他添加新项目时,它将链接到insertnewquote.php,但是我需要在insertnewquote中保留名称和数据.php因此,用户不需要重新键入名称和日期。

尝试在线搜索,我可以找到带有下拉列表的示例,但是我的下拉列表来自我的数据库,因为随着用户输入新客户,下拉列表中的项目可能会增加。

插入报价.php

<!doctype html> 
<html> 
<head> 
<meta charset="utf-8"> 
<link rel="stylesheet" href="Mainpage.css" type="text/css" /> 
<title>Chiorino</title> 
<script type="text/javascript" src="validation/jquery.min.js"></script>
<script type="text/javascript" src="validation/jquery.validate.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#insertquotation-form").validate({
    rules: {
        quotation_date: {
        required: true
        },
        
        quantity: {
        required: true,
        number: true,
        minlength:1
        },
        
        length: {
        required: true,
        number: true,
        minlength:1
        },
        
        width: {
        required: true,
        number: true,
        minlength:1
        },
        
        height: {
        required: true,
        number: true,
        minlength:1
        },
        
        unitprice: {
        required: true,
        number: true,
        minlength:1
        }
    
        
    }
});
});
</script>
</head> 
<body> 
<?php 
include('connect.php');      
$sql="SELECT cust_name from customer"; 
$result=mysql_query($sql); 
?> 
<form id="insertquotation-form" name="insertquotation-form" class="login-form"        action="insertquotationprocess.php" method="post"> 
  
    <div class="header"> 
    <h1>Insert Quotation</h1> 
    </div> 
  
    <div class="content"> 
    <input name="quotation_date" type="date" class="input username" placeholder="Date"  /> 
      
    <?php 
    echo "<select name='cust_name' class='input password'>"; 
    echo "<option value=''>Select Customer</option>"; 
    while ($row = mysql_fetch_array($result)) { 
    echo "<option value='" . $row['cust_name'] ."'>" . $row['cust_name'] ."</option>";}  
    echo "</select>"; 
    ?> 
    <a href="insertcustomer.php"><br>Add new Customer</a> 
      
    <?php 
    include('connect.php');      
    $sql="SELECT product_type from product"; 
    $result=mysql_query($sql); 
    ?> 
          
    <?php 
    echo "<select name='product_type' class='input password'>"; 
    echo "<option value=''>Select Product</option>"; 
    while ($row = mysql_fetch_array($result)) { 
    echo "<option value='" . $row['product_type'] ."'>" . $row['product_type'] ." </option>";}  
    echo "</select>"; 
    ?> 
    <a href="insertsproduct.php"><br>Add new Product</a>   
      
    <input name="quantity" type="number" class="input password" placeholder="Quantity" /> 
      
    <input name="length" type="number" class="input password" placeholder="Length" /> 
    <select name="lengthunit" class="input password"> 
    <option value="">Units</option> 
    <option value="mm">mm</option> 
    <option value="cm">cm</option> 
    <option value="m">m</option> 
    </select> 
      
    <input name="width" type="number" class="input password" placeholder="Width" /> 
    <select name="widthunit" class="input password"> 
    <option value="">Units</option> 
    <option value="mm">mm</option> 
    <option value="cm">cm</option> 
    <option value="m">m</option> 
    </select> 
      
    <input name="height" type="number" class="input password" placeholder="Height" /> 
    <select name="heightunit" class="input password"> 
    <option value="">Units</option> 
    <option value="mm">mm</option> 
    <option value="cm">cm</option> 
    <option value="m">m</option> 
    </select> 
    
    <input name="unitprice" type="number" class="input password" step="0.01" min="0.01"  placeholder="Unit Price" /> 
    <select name="currency" class="input password"> 
    <option value="">Currency</option> 
    <option value="SGD">SGD</option> 
    <option value="USD">USD</option> 
    <option value="RMB">RMB</option> 
    </select> 
      
    <input name="notation" type="text" class="input password" placeholder="Notation" /> 
      
    </div> 
    <div class="footer"> 
    <input type="submit" name="Submit" value="Submit" class="button" /> 
    <a href="quotationsub.php"><input type="button" class="register" value="Back" /> </a> 
    </div> 
</div> 
<div class="gradient"></div> 
   
 </form> 
</body> 
</html>

插入报价流程.php

<!doctype html> 
<html> 
<head> 
<meta charset="utf-8">
<link rel="stylesheet" href="Mainpage.css" type="text/css" />
<title>Chiorino</title> 
</head> 
<body> 
<div id="wrapper">
<?php 
include("connect.php"); 
$quotation_date=mysql_real_escape_string($_POST['quotation_date']); 
$cust_name=mysql_real_escape_string($_POST['cust_name']); 
$product_type=mysql_real_escape_string($_POST['product_type']); 
$quantity = mysql_real_escape_string($_POST['quantity']); 
$length = mysql_real_escape_string($_POST['length']); 
$lengthunit = mysql_real_escape_string($_POST['lengthunit']); 
$width = mysql_real_escape_string($_POST['width']); 
$widthunit = mysql_real_escape_string($_POST['widthunit']); 
$height = mysql_real_escape_string($_POST['height']); 
$heightunit = mysql_real_escape_string($_POST['heightunit']);
$unitprice = mysql_real_escape_string($_POST['unitprice']);
$notation = mysql_real_escape_string($_POST['notation']); 
$confirm = "1";
$total = $quantity*$unitprice;
$currency = mysql_real_escape_string($_POST['currency']);
if(empty($quotation_date)||empty($cust_name)||empty($product_type)||empty($quantity)) 
{ 
echo"<form class='login-form'>";
    echo"<div class='header'>";
    echo"<h1>Sorry, please key in all columns</h1>";
    echo"</div>";
echo"<div class='footer'>";
echo" <a href='insertquotation.php'><input type='button' class='button'         value='Back' /></a>";
echo"</div>";
exit; 
} 

$sql="INSERT INTO     quotation(quotation_date,cust_name,product_type,quantity,length,lengthunit,width,widthunit,    height,heightunit,unitprice,notation,total,currency,confirm) VALUES     ('$quotation_date','$cust_name','$product_type','$quantity','$length','$lengthunit','$width    ','$widthunit'
,'$height','$heightunit','$unitprice','$notation','$total','$currency','$confirm')"; 
$result1=mysql_query($sql); 
if(!$result1){ 
die('Cannot run the query : '.$sql. "---" . mysql_error()); 
exit; 
} 
echo"<form class='login-form'>";
    echo"<div class='header'>";
    echo"<h1>Quotation Added</h1>";
    echo"</div>";
echo"<div class='footer'>";
echo" <a href='insertnewquotation.php?name=$cust_name'><input type='button' class='button' value='Add New Items' /></a>";   
echo" <a href='quotationlist.php'><input type='button' class='button' value='Back'     /></a>";
echo"</div>"; 
$item = "1";
$list=" SELECT * FROM quotationlist WHERE quotation_date = '$quotation_date' AND     cust_name = '$cust_name'";
$list1=mysql_query($list);
if(!$list1){
die('Cannot run the query : '.$query. "---" . mysql_error());
exit;
}
if(mysql_num_rows($list1)>0)
{ 
$add2 = "UPDATE quotationlist SET item = item + 1 WHERE quotation_date =     '$quotation_date' AND cust_name = '$cust_name'";
$result3=mysql_query($add2);
if(!$result3){
die('Cannot run the query : '.$sql. "---" . mysql_error());
exit;
}}
else{
$add=" INSERT INTO quotationlist (quotation_date,cust_name,item) VALUES     ('$quotation_date','$cust_name','$item')";
$result2=mysql_query($add);
if(!$result2){
die('Cannot run the query : '.$sql. "---" . mysql_error());
exit;
}}  


?> 
</body> 
</html>

插入新报价.php

<!doctype html> 
<html> 
<head> 
<meta charset="utf-8"> 
<link rel="stylesheet" href="Mainpage.css" type="text/css" /> 
<title>Chiorino</title> 
<script type="text/javascript" src="validation/jquery.min.js"></script>
<script type="text/javascript" src="validation/jquery.validate.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#insertquotation-form").validate({
    rules: {
        quotation_date: {
        required: true
        },
        
        quantity: {
        required: true,
        number: true,
        minlength:1
        },
        
        length: {
        required: true,
        number: true,
        minlength:1
        },
        
        width: {
        required: true,
        number: true,
        minlength:1
        },
        
        height: {
        required: true,
        number: true,
        minlength:1
        },
        
        unitprice: {
        required: true,
        number: true,
        minlength:1
        }
    
        
    }
});
});
</script>
</head> 
<body> 
<?php 
include('connect.php');      
$sql="SELECT cust_name from customer"; 
$result=mysql_query($sql); 
?> 
<form id="insertquotation-form" name="insertquotation-form" class="login-form"        action="insertquotationprocess.php" method="post"> 
  
    <div class="header"> 
    <h1>Insert Quotation</h1> 
    </div> 
  
    <div class="content"> 
    <input name="quotation_date" type="date" class="input username" placeholder="Date"  /> 
   <?php
   // Get Customer Name and Filter
  $custName = isset( $_GET['cust_name'] ) ? strip_tags($_GET['cust_name']) : "";
  ?>
  <input name="custname" 
   type="text" 
   value="<?php echo($custName); ?>"/> 
    <a href="insertcustomer.php"><br>Add new Customer</a> 
      
    <?php 
    include('connect.php');      
    $sql="SELECT product_type from product"; 
    $result=mysql_query($sql); 
    ?> 
          
    <?php 
    echo "<select name='product_type' class='input password'>"; 
    echo "<option value=''>Select Product</option>"; 
    while ($row = mysql_fetch_array($result)) { 
    echo "<option value='" . $row['product_type'] ."'>" . $row['product_type'] ." </option>";}  
    echo "</select>"; 
    ?> 
    <a href="insertsproduct.php"><br>Add new Product</a>   
      
    <input name="quantity" type="number" class="input password" placeholder="Quantity" /> 
      
    <input name="length" type="number" class="input password" placeholder="Length" /> 
    <select name="lengthunit" class="input password"> 
    <option value="">Units</option> 
    <option value="mm">mm</option> 
    <option value="cm">cm</option> 
    <option value="m">m</option> 
    </select> 
      
    <input name="width" type="number" class="input password" placeholder="Width" /> 
    <select name="widthunit" class="input password"> 
    <option value="">Units</option> 
    <option value="mm">mm</option> 
    <option value="cm">cm</option> 
    <option value="m">m</option> 
    </select> 
      
    <input name="height" type="number" class="input password" placeholder="Height" /> 
    <select name="heightunit" class="input password"> 
    <option value="">Units</option> 
    <option value="mm">mm</option> 
    <option value="cm">cm</option> 
    <option value="m">m</option> 
    </select> 
    
    <input name="unitprice" type="number" class="input password" step="0.01" min="0.01"  placeholder="Unit Price" /> 
    <select name="currency" class="input password"> 
    <option value="">Currency</option> 
    <option value="SGD">SGD</option> 
    <option value="USD">USD</option> 
    <option value="RMB">RMB</option> 
    </select> 
      
    <input name="notation" type="text" class="input password" placeholder="Notation" /> 
      
    </div> 
    <div class="footer"> 
    <input type="submit" name="Submit" value="Submit" class="button" /> 
    <a href="quotationsub.php"><input type="button" class="register" value="Back" /> </a> 
    </div> 
</div> 
<div class="gradient"></div> 
   
 </form> 
</body> 
</html>

我怎样才能继续更改我的代码,以便在我在插入报价过程中按添加新产品时保留名称和数据.php

非常感谢

我猜这是您正在单击的链接,需要它来传递值?

echo "<a href='insertnewquotation.php'><input type='button' class='button' value='Add New Items' /></a>";

只需将查询字符串变量附加到 URL 即可,以便 insertnewquote.php 文件接收它们,如下所示:

echo "<a href='insertnewquotation.php?name=$cust_name&producttype=$product_type...'

然后在插入新报价中.php您可以使用以下内容检索它们:

$cust_name = isset( $_GET['cust_name'] ) ? $_GET['cust_name'] : "";

希望这能为你指明正确的方向。

注意:我什至不会触及已弃用的mysql_*函数的使用,因为这是一个学校项目。


编辑

在输入中,您必须分配 value 属性并在适当的情况下使用 PHP 标签:

<?php
   // Get Customer Name and Filter
   $custName = isset( $_GET['cust_name'] ) ? strip_tags($_GET['cust_name']) : "";
?>
<input name="custname" 
       type="text" 
       value="<?php echo($custName); ?>"> 

注意:在筛选之前使用原始查询变量通常不是一个好主意。在这种情况下,它没有问题,但永远不要在数据库查询中使用原始查询字符串数据。那只是要求SQL注入。