Jump to content

Recommended Posts

Hello,

 

I am currently creating an online with good intergration for checkoing out, I have assigned variables that are placed into to hidden fields and sent to google, the problem arises when the loop kicks in, as it resets the variables and reassignes them to the old value rather than the next values,

 

// Print each item.
$total = 0; // Total cost of the order.
while ($row = mysql_fetch_array ($result)) {

	$count = $count+1;
	$subtotal = $_SESSION['cart'][$row['product_id']]['quantity'] * $_SESSION['cart'][$row['product_id']]['price'];
	$total += $subtotal;

	//setting table variables
	$catname = $row['category_name'];
	$prodname = $row['product_name'];
	$price = $_SESSION['cart'][$row['product_id']]['price'];
	$quantity = $_SESSION['cart'][$row['product_id']]['quantity'];

	// Print the row.
	echo "	<tr>
	<td align=\"left\" bgcolor=\"#cccccc\">{$row['category_name']}</td>
	<td align=\"left\" bgcolor=\"#cccccc\">{$row['product_name']}</td>
	<td align=\"right\" bgcolor=\"#cccccc\">£{$_SESSION['cart'][$row['product_id']]['price']}</td>
	<td align=\"center\" bgcolor=\"#cccccc\"><input type=\"text\" size=\"3\" name=\"qty[{$row['product_id']}]\" value=\"{$_SESSION['cart'][$row['product_id']]['quantity']}\" /></td>
	<td align=\"right\" bgcolor=\"#cccccc\">£" . number_format ($subtotal, 2) . "</td>
</tr>\n";
} // End of the WHILE loop.

mysql_close($dbc); // Close the database connection.

// close the table, and the form.
echo '	<tr>
	<td colspan="4" align="right"><b>Total:<b></td>
	<td align="right">£' . number_format ($total, 2) . '</td>
</tr>
</table><div align="center"><input type="submit" name="submit" value="Update My Cart" />	
<input type="hidden" name="submitted" value="TRUE" />
</form><br /><br />';
?>
<?php
} else {
echo '<p>Your cart is currently empty.</p>';
}	
?>
<?php
echo"<form id=\"googlecheckout\" method=\"POST\" action = \"https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/453070710704027\"
accept-charset=\"utf-8\">";
while ($count > 0)
{
echo"<input type=\"hidden\" name=\"item_description_$count\" value=\"$catname\" />
<input type=\"hidden\" name=\"item_name_$count\" value=\"$prodname\" />
<input type=\"hidden\" name=\"item_price_$count\" value=\"$price\" />
<input type=\"hidden\" name=\"item_quantity_$count\" value=\"$quantity\"/>
<input type=\"hidden\" name=\"item_currency_$count\" value=\"GBP\"/>";
$count --;
}
echo "<input type=\"image\" name=\"Google Checkout\" alt=\"Fast checkout through Google\"
src=\"http://checkout.google.com/buttons/checkout.gif?merchant_id=453070710704027&w=180&h=46&style=white&variant=text&loc=en_US\"
height=\"46\" width=\"180\"/>
</form>";

echo $row;
?>

 

A live version can be here

http://www.jetexed.org.uk/store

 

forgive me for the basd coding I am self taught and still learning.

Link to comment
https://forums.phpfreaks.com/topic/102706-can-somebody-help-me/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.