Hi all,
I am REALLY trying to understand the POST technique for passing variables to the next page.
I have a login that leads to a welcome page. That page gets all the users info from MySQL and displays their name and welcome.
What I am tring to do is pass their ID from the mysql DB to my order page, which will look up al ltheir items from the table. (This page works great when I use it with the ID preset)
The challenge I am having is passing the ID from the welcome page to the order page.
Here is the code for the welcome page (this will display their ID and name, but doesn't seem to pass the ID to the next page [order.php]).
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form name="order" method="post" action="order5.php">
<?php
$hostname = "localhost";
$database = "a";
$username = "b";
$password = "c";
$connpt = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database, $connpt);
// check that both formfields are supplied
if($_POST['UserName'] && $_POST['pass1'])
{
$username = htmlspecialchars($_POST['UserName']);
$password= htmlspecialchars($_POST['pass1']);
$verify=mysql_query("select * from users where password='$password' and username='$username'");
while($row = mysql_fetch_array($verify, MYSQL_ASSOC)) {
$ID = $row['ID'];
$Company = $row['Company'];
$FirstName = $row['FirstName'];
$LastName = $row['LastName'];
$EmailAddress = $row['EmailAddress'];
$UserName = $row['UserName'];
$Password = $row['Password'];
$DealerID = $row['DealerID'];
$URL = $row['URL'];
}
// if match found
if(mysql_num_rows($verify)==1)
{
// goto users area link or redirect
echo "Hello ".$FirstName." ".$LastName."<br><br>"."Welcome back!";
}
// if no match
else
{
print "No user with that username or password found";
}
}
// if one or both form fields are missing
else
{
print "Both username and password fields are required..";
}
?>
<br>
<input type="hidden" name="order" value="<?= $_POST['order'] ?>">
<input type="hidden" name="DealerID" value="<?= $_POST['DealerID'] ?>">
<input type="submit" name="Submit" value="Go to Order Page">
</form>
</body>
</html>
Here is the code for the order.php page that works with the ID hardcoded, but isn't getting the ID from the welcome.php page above.
<html>
<head><title>Online Sign Ordering</title></head>
<body>
<?php
$hostname = "localhost";
$database = "a";
$username = "b";
$password = "c";
$path = "images/";
$Dealer = $_POST['DealerID'];
$order = $_POST['order'];
echo $Dealer;
echo "The Dealer ID is ".$DealerID;
echo $order;
print_r($_POST);
$connpt = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database, $connpt);
?>
<form action="process4.php" method="post" name="SignOrder" id="SignOrder">
<?php
if(isset($_POST['order']))
{ ?>
<table>
<tr>
<td width="100">ID</td>
<td width="100">Item Name</td>
<td width="150">Item Description</td>
<td width="150">Body Copy</td>
<td width="100">Price</td>
<td width="100">Image</td>
<td width="150">Order</td>
<td width="150">Quantity</td>
</tr>
<?php
$result = mysql_query("SELECT * FROM dealeritems WHERE DealerID='$DealerID'");
while($row = mysql_fetch_assoc($result)) {
?>
<tr>
<td width="100"><?php echo $row['ID']; ?></td>
<td width="100"><?php echo $row['ItemName']; ?></td>
<td width="150"><?php echo $row['ItemDescription']; ?></td>
<td width="150"><?php echo $row['BodyCopy']; ?></td>
<td width="150"><?php echo "$".$row['Price']; ?></td>
<input type="hidden" name="price_<?php echo $row['ID']; ?>" value="<?php echo $row['Price']; ?>">
<td width="100"><img src="<?php echo $path.$row['ImageName']; ?>" width="100" height="125"></td>
<td width="150">
<input name="order[]" type="checkbox" value="<?php echo $row['ID']; ?>">
<!-- Aside: include hidden itemnames to be used
in the 'thank you for your order message' -->
<input type="hidden" name="name_<?php echo $row['ID']; ?>" value="<?php echo $row['ItemName']; ?>">
</td>
<td width="150">
<select name="quantity_<?php echo $row['ID']; ?>">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</td>
</tr>
<?php
} ?>
<?php } ?>
</table>
<p>
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Reset">
</p>
</form>
</body>
</html>
As you can see, I am echoing the DealerID and doing a print_r for the POST to see if it is coming thru and it is not.
I know I am close.
I appreciate the help, it makes it easier to learn when someone with applied knowledge gives some direction to users like myself.
Thanks,
Don