I am doing my school project and I have this problem After my user input the first quotation form(insertquotation.php), and submit, it will bring him to insertquotationprocess.php which will tell him that the order is added. And then he can choose to add new items to the invoice or go back. When he add new item, it will link to insertnewquotation.php, however I need the name and the data to be retain in the insertnewquotation.php therefore, the user need not re-type the name and date.
I have tried to search online, i could find example with dropdown list, however my dropdown list is derived from my database as the items in the dropdown list can increased as the user input new customer.
insertquotation.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>
insertquotationprocess.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>
insertnewquotation.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>
how can i go along to change my code so that the name and data will be retain when i press add new products at insertquotationprocess.php
With many thanks
I'm guessing this is the link that you are clicking and need to it to pass on values?
echo "<a href='insertnewquotation.php'><input type='button' class='button' value='Add New Items' /></a>";
It's simply a matter of appending query string variables to the URL so that the insertnewquotation.php file receives them like:
echo "<a href='insertnewquotation.php?name=$cust_name&producttype=$product_type...'
Then in the insertnewquotation.php you can retrieve them with something like:
$cust_name = isset( $_GET['cust_name'] ) ? $_GET['cust_name'] : "";
Hope that points you in the right direction.
Note: I won't even touch the usage of deprecated mysql_*
functions since this is a school project.
EDIT
In your input, you have to assign the value attribute and use PHP tags where appropriate:
<?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); ?>">
NOTE: It is generally not a good idea to use raw query variables before filtering. In this case it is not that problematic, but never ever use raw query string data in a database query. That's just asking for SQL Injection.