The code below has 8 $_POST variables containing user registration data. The code below also features a promo code text field, when users enter a promo code and try to update, I lose the values of the 8 $_POST variables that contained user registration data. I was wondering if there was a way to not lose that data?
<?php
session_start();
//Create mysql connect variable
$conn = mysql_connect('host', 'root', 'raycharles');
//kill connection if error occurs
if(!$conn){
die('Error: Unable to connect.' . '<br>' . mysql_error());
}
//connect to mysql database
mysql_select_db("wibldard", $conn);
//GET PROMO CODES FROM DB
$promo_results = mysql_query("SELECT * FROM promo",$conn);
while($promo_row = mysql_fetch_array($promo_results)){
echo $promo_row['promo_code'];
}
if(isset($_GET['promo'])){
echo $_GET['promo'];
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!-- JAVASCRIPT -->
<script type="text/javascript" src="js/jquery.js"></script>
<!-- STYLES & FONTS -->
<link rel="stylesheet" type="text/css" href="css/style.css" />
<!--JQUERY-->
<script type="text/javascript">
$(document).ready(function(){
$("#mainsearchfield").Watermark("");
});
</script>
</head>
<body>
<div id="main-container">
<?php include('inc/menu.inc.php'); ?>
<div id="body-container" style="padding-bottom:150px; height:800px;">
<div style="height:100px; margin:0px auto;">
<img class="reg-step" style="width:100%;" src="images/step2.png">
</div>
<?php
//echo 'e-mail :' . $_POST['email'] . '<br/>' . 'password :' . $_POST['password'] . '<br/>' . 'city: ' . $_POST['city'] . '<br/>' . 'state: ' . $_POST['state'] . '<br/>' . 'phone: ' . $_POST['phone'] . '<br/>' . 'first name: '. $_POST['fname'] . '<br/>' . 'last name: ' . $_POST['lname'] . '<br/>company: ' . $_POST['company-name'] ;
$_SESSION['email'] = $_POST['email'];
$_SESSION['password'] = $_POST['password'];
$_SESSION['city'] = $_POST['city'];
$_SESSION['state'] = $_POST['state'];
$_SESSION['phone'] = $_POST['phone'];
$_SESSION['first'] = $_POST['fname'];
$_SESSION['last'] = $_POST['lname'];
$_SESSION['compname'] = $_POST['compname'];
?>
<span style="font-size:22px; color:blue; font-weight:bold; margin-left:100px;"> Invoice </span>
<div style="width:900px; height:500px; border:1px solid #ddd; margin-left:100px;">
<table id="registration-table1">
<!-- Results table headers -->
<tr style="background-color:lightblue;">
<th>Date</th>
<th>Product</th>
<th style="width:50px;">Qty</th>
<th>Cost</th>
</tr>
<tr>
<td style="width:120px;"><?php echo date("m/d/y");?></td>
<td style="width:570px; text-align:left; padding-left:10px;">
<a href="#">Apples</a>
</td>
<td style="text-align:center; padding-bottom:120px;">1</td>
<td style="width:150px; padding-bottom:120px; text-align:center;">$59.99</td>
</tr>
</table>
<div style="float:left; width:350px; font-size:12px; padding:10px;">*An order confirmation e-mail will be sent out to the address provided upon payment authorization.</div>
<table id="registration-table2">
<tr>
<td style="font-weight:bold; width:140px; padding:10px; padding-right:20px;">Promo Code:</td>
<td class="table2-cell">
<form method="get" action="registernewstep2.php">
<input name="promo" style="width:90px; margin-right:7px; margin:5px;" type="text" /><br/>
<input type="submit" style="margin-bottom:5px;" value="update"/>
</form>
</td>
</tr>
<tr>
<td class="table2-heading-cell">Delivery:</td>
<td class="table2-cell"><i>Electronic</i></td>
</tr>
<tr>
<td class="table2-heading-cell">Shipping:</td>
<td class="table2-cell">$0.00</td>
</tr>
<tr>
<td class="table2-heading-cell">Tax:</td>
<td class="table2-cell">$0.00</td>
</tr>
<tr>
<td class="table2-heading-cell">Total:</td>
<td class="table2-cell">$59.99</td>
</tr>
<tr>
<td style="font-weight:bold; padding:10px; border:none;"></td>
<td style="text-align:center; border:none; padding-top:20px;">
<!--CHECKOUT BUTTON-->
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="johnnycage9@gmail.com">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="apples">
<input type="hidden" name="item_number" value="1701">
<input type="hidden" name="amount" value="1.00">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="tax_rate" value="0.000">
<input type="hidden" name="shipping" value="0.00">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynow_SM.gif:NonHostedGuest">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_SM.gif" style="border:1px solid #fff;" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
</td>
</tr>
</table>
</div>
<?php include('inc/footer.inc.php');
echo'
</div>
</body>
</html>';
The $_POST variables are only “posted” to the page that is displayed, so when your user enters and submits the promo code, you’re not currently posting the values that you’re missing.
To do that, you’ll need to add some hidden fields to the form that is being submitted. The form field names have to be the same as the $_POST variable, and the value of each field should be the value from the posted field like this: