s_ainley87 Posted April 13, 2008 Share Posted April 13, 2008 Hello Everyone, I am currently intergrating my website with google checkout, since I have made this work my update cart has stopped working, can anybody see why, any help would be greatly recieved. <?php session_start() ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>JetStore :: Shopping With Jetexed Corporation Ltd</title> <link href="CSS/jetstorelayout.css" rel="stylesheet" type="text/css" /> <?php require_once ('include/mysql_connect.php'); ?> </head> <body> <div id="wrapper"> <div id="header"> <img src="images/jetstore_header.gif" alt="Welcome To JetStore"/> </div> <div id="navigation"> <!--Class CURRENT must be changed for each page--> <ul class="jetnav"> <li><a href="index.php"><b>Home</b></a></li> <li><a href="adobe.php"><b>Adobe Software</b></a></li> <li><a href="microsoft.php"><b>Microsoft Software</b></a></li> <li><a href="security.php"><b>PC Security</b></a></li> <li><a href="digital.php"><b>Digital Photography</b></a></li> <li><a href="mp3.php"><b>Mp3 Players</b></a></li> <li><a href="books.php"><b>Books</b></a></li> </ul> </div> <div id="login"> <div class="rounded"> <div class="top"><div class="right"></div></div> <div class="middle"><div class="right"> <div class="content"> <!--Content Here--> <!--<form id="loginform" name="login" method="post" action="processlogin.php"> <strong>Email:</strong> <input type="text" name="email" <?php if (isset($_POST['email'])) echo $_POST['email']; ?>/><br /><br /> <strong>Password:</strong> <input type="password" name="password"/><br /> <input type="submit" name="submit" value="Login" /> <input type="button" onClick="parent.location='register.php'" value="Register"> <input type="hidden" name="submitted" value="TRUE" /> </form>--><br /> <hr /> <br /> <h2>User Links</h2><br /> <a href = "details.php" class="links">My Details </a><br /> <a href = "view_cart.php" class="links">My Basket </a><br /> <a href = "checkout.php" class="links">Checkout </a><br /> <a href = "logout.php" class="links">Log Out </a><br /> <a href = "contact.php" class="links">Contact Us </a><br /> </div> </div></div> <div class="bottom"><div class="right"></div></div> </div> </div> <div id="main"> <div class="rounded"> <div class="top"><div class="right"></div></div> <div class="middle"><div class="right"> <div class="content"> <!--Content Here--> <?php //this page dispalys the contents of the shopping basket //this page also lets the user update the contents of their basket // Check if the form has been submitted (to update the cart). if (isset($_POST['submitted'])) { // Check if the form has been submitted. // Change any quantities. foreach ($_POST['qty'] as $k => $v) { // Must be integers! $pid = (int) $k; $qty = (int) $v; if ( $qty == 0 ) { // Delete. unset ($_SESSION['cart'][$pid]); } elseif ( $qty > 0 ) { // Change quantity. $_SESSION['cart'][$pid]['quantity'] = $qty; } } // End of FOREACH. } // End of SUBMITTED IF. // Check if the shopping cart is empty. $empty = TRUE; if (isset ($_SESSION['cart'])) { foreach ($_SESSION['cart'] as $key => $value) { if (isset($value)) { $empty = FALSE; break; // Leave the loop. } } // End of FOREACH. } // End of ISSET IF. // Display the cart if it's not empty. if (!$empty) { require_once ('include/mysql_connect.php'); // Connect to the database. // Retrieve all of the information for the prints in the cart. $query = "SELECT category.category_name, product.product_id, product.product_name FROM category, product WHERE category.category_id = product.category_id AND product.product_id IN ("; foreach ($_SESSION['cart'] as $pid => $value) { $query .= $pid . ','; } $query = substr ($query, 0, -1) . ') ORDER BY product.product_id ASC'; $result = mysql_query ($query, $dbc); // Create a table and a form. echo '<table border="0" width="90%" cellspacing="3" cellpadding="3" align="center"> <tr> <td align="left" width="30%" bgcolor="#FF6600"><b>Category</b></td> <td align="left" width="30%" bgcolor="#FF6600"><b>Product Name</b></td> <td align="right" width="10%" bgcolor="#FF6600"><b>Price</b></td> <td align="center" width="10%" bgcolor="#FF6600"><b>Qty</b></td> <td align="right" width="10%" bgcolor="#FF6600"><b>Total Price</b></td> </tr> '; // Print each item. $total = 0; // Total cost of the order. $count = 0; // Count the position in the basket for google while ($row = mysql_fetch_array ($result)) { // Calculate the total and sub-totals and position $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']; ?> <form id="googlecheckout" method="POST" action = "https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/453070710704027" accept-charset="utf-8"> <?php echo "<tr> <td align=\"left\" bgcolor=\"#cccccc\"> $catname <input type=\"hidden\" name=\"item_description_$count\" value=\"$catname\" /> </td> <td align=\"left\" bgcolor=\"#cccccc\"> $prodname <input type=\"hidden\" name=\"item_name_$count\" value=\"$prodname\" /> </td> <td align=\"right\" bgcolor=\"#cccccc\"> £$price <input type=\"hidden\" name=\"item_price_$count\" value=\"$price\" /> </td> <td align=\"center\" bgcolor=\"#cccccc\"> <input type=\"text\" size=\"3\" name=\"qty[{$row['product_id']}]\" value= $quantity /> <input type=\"hidden\" name=\"item_quantity_$count\" value=\"$quantity\"/> </td> <input type=\"hidden\" name=\"item_currency_$count\" value=\"GBP\"/> <td align=\"right\" bgcolor=\"#cccccc\">£" . number_format ($subtotal, 2) . "</td> </tr>\n" ; ?> <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> <?php } // End of the WHILE loop. mysql_close($dbc); // Close the database connection. // Print the footer, close the table, and the form. echo ' </table> <form id="update" action="view_cart.php" method="post"> <table> <tr> <td colspan="4" align="right"> <b>Total:<b> </td> <td align="right"> £' . number_format ($total, 2) . ' </td> </tr> <div align="center"><input type="submit" name="submit" value="Update My Cart" /> <input type="hidden" name="submitted" value="TRUE" /> </table> </form> </div>'; } else { echo '<p>Your cart is currently empty.</p>'; } //first </table> closes shopping cart table ?> </div> </div> </div></div> <div class="bottom"><div class="right"></div></div> </div> </div> <div id="footer"> <div class="rounded"> <div class="top"><div class="right"></div></div> <div class="middle"><div class="right"> <div class="content"> <!--Content Here--> </div> </div></div> <div class="bottom"><div class="right"></div></div> </div> </div> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/100955-problem-with-forms/ Share on other sites More sharing options...
dezkit Posted April 13, 2008 Share Posted April 13, 2008 what errors u get Link to comment https://forums.phpfreaks.com/topic/100955-problem-with-forms/#findComment-516325 Share on other sites More sharing options...
s_ainley87 Posted April 13, 2008 Author Share Posted April 13, 2008 I get this error Warning: Invalid argument supplied for foreach() in /home/jetexed/public_html/store/view_cart.php on line 78 Link to comment https://forums.phpfreaks.com/topic/100955-problem-with-forms/#findComment-516326 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.