Jump to content

Passing Data From Page To Page


smallc28

Recommended Posts

I would like some help or some suggestions....I've created an dropdown form for my clothing site which has Small Medium and Large in it..When an customer select from Small, Medium, or Large...that information/data will then be pass from my product.php to my cart.php................I've place both codes from my product.php and cart.php

<?php
// Check to see the URL variable is set and that it exists in the database
if (isset($_GET['id'])) {
// Connect to the MySQL database
include "storescripts/connect_to_mysql.php";
$id = preg_replace('#[^0-9]#i', '', $_GET['id']);
// Use this var to check to see if this ID exists, if yes then get the product
// details, if no then exit this script and give message why
$sql = mysql_query("SELECT * FROM products WHERE id='$id' LIMIT 1");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
// get all the product details
while($row = mysql_fetch_array($sql)){
$product_name = $row["product_name"];
$price = $row["price"];
$details = $row["details"];
$category = $row["category"];
$subcategory = $row["subcategory"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));

}

} else {
echo "That item does not exist.";
exit();
}

} else {
echo "Data to render this page is missing.";
exit();
}
mysql_close();
?>

 

<body>
<div align="center" id="mainWrapper">
<div id="pageContent">
<table width="100%" border="0" cellspacing="0" cellpadding="15">
<tr>
<td width="19%" valign="top"><img src="inventory_images/<?php echo $id; ?>.jpg" width="142" height="188" alt="<?php echo $product_name; ?>" /><br />
<a href="inventory_images/<?php echo $id; ?>.jpg">View Full Size Image</a></td>
<td width="81%" valign="top"><h3><?php echo $product_name; ?></h3>
<p><?php echo "$".$price; ?><br />
<br />
<?php echo "$subcategory $category"; ?> <br />
<br />
<?php echo $details; ?>
<br />
</p>
<form id="form1" name="form1" method="post" action="cart.php">
<table width="70%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td align="left">Select Your Size</td>
<td>
<label width="0%">
<select name="category" id= <?php echo "$category";?>">
<option value="<?php echo $details; ?> ">Small</option>
<option value="<?php echo $details; ?>">Medium</option>
<option value="<?php echo $details; ?>">Large</option>
</select>
</label>
</tr>
<tr>
<td> </td>
<td>
</tr>
</table>				
</form>
</tr>
</table>
<form id="form1" name="form1" method="post" action="cart.php">
<input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" />
<input type="submit" name="button" id="button" value="Add to Shopping Cart" />
</form>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>	   $cartOutput = "";
$cartTotal = "";
$pp_checkout_btn = '';
$product_id_array = '';
if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) {
$cartOutput = "<h2 align='center'>Your shopping cart is empty</h2>";
} else {
// Start PayPal Checkout Button
$pp_checkout_btn .= '<form action="[url="https://www.paypal.com/cgi-bin/webscr"]https://www.paypal.com/cgi-bin/webscr[/url]" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="[email="BLAMBLAM@SOMEEMAIL.COM"]BLAMBLAM@SOMEEMAIL.COM'[/email];
// Start the For Each loop
$i = 0;
foreach ($_SESSION["cart_array"] as $each_item) {
 $item_id = $each_item['item_id'];
 $sql = mysql_query("SELECT * FROM products WHERE id='$item_id' LIMIT 1");
 while ($row = mysql_fetch_array($sql)) {
  $product_name = $row["product_name"];
  $price = $row["price"];
  $details = $row["details"];
 }
 $shipTotal="10.00";
			$taxrate  ="0.06";
			$pricetotal = $price * $each_item['quantity'];
			$gettax = $price * $taxrate;
 $cartTotal = $pricetotal + $gettax + $shipTotal + $cartTotal;
 setlocale(LC_MONETARY, "en_US");
	$pricetotal = money_format("%10.2n", $pricetotal);
 // Dynamic Checkout Btn Assembly
 $x = $i + 1;
 $pp_checkout_btn .= '<input type="hidden" name="item_name_' . $x . '" value="' . $product_name . '">
			<input type="hidden" name="amount_' . $x . '" value="' . $price . '">
			<input type="hidden" name="quantity_' . $x . '" value="' . $each_item['quantity'] . '">
			<input type="hidden" name="shipping_'. $x . '"value="'. $shipTotal .'">
			<input type="hidden" name="tax_'. $x . '"value="'. $taxrate * $price .'"> ';
 // Create the product array variable
 $product_id_array .= "$item_id-".$each_item['quantity'].",";
 // Dynamic table row assembly
 $cartOutput .= "<tr>";
 $cartOutput .= '<td><a href="product.php?id=' . $item_id . '">' . $product_name . '</a><br /><img src="inventory_images/' . $item_id . '.jpg" alt="' . $product_name. '" width="40" height="52" border="1" /></td>';
 $cartOutput .= '<td>' . $details . '</td>';
 $cartOutput .= '<td>$' . $price . '</td>';
 $cartOutput .= '<td><form action="cart.php" method="post">
 <input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" />
 <input name="adjustBtn' . $item_id . '" type="submit" value="change" />
 <input name="item_to_adjust" type="hidden" value="' . $item_id . '" />
 </form></td>';
 //$cartOutput .= '<td>' . $each_item['quantity'] . '</td>';
 $cartOutput .= '<td>' . $pricetotal . '</td>';
 $cartOutput .= '<td><form action="cart.php" method="post"><input name="deleteBtn' . $item_id . '" type="submit" value="X" /><input name="index_to_remove" type="hidden" value="' . $i . '" /></form></td>';
 $cartOutput .= '</tr>';
 $i++;
}

Link to comment
https://forums.phpfreaks.com/topic/271135-passing-data-from-page-to-page/
Share on other sites

One or two problems are immediately apparent.

 

The form with the size selection has method=POST, your other page uses GET

That form has no submit button to send the data, you have put that in a separate form.

When you do get to eventually send the data, all your size options will have the same value (ie $details) instead of small, medium and large

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.