Jump to content

no errors while testing on a local server. Variable errors when live. HELP PLEASE!


Recommended Posts


First off this cart mentioned below is for a online cart and works perfectly on a local server such as xammp, how ever when i up load it to a live server it all the variables in the cart out throws errors. Has anyone encounter this problem?


Heres my code for the cart render:

$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="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_cart">
    <input type="hidden" name="upload" value="1">
    <input type="hidden" name="business" value="you@youremail.com">';
// 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"];
$pricetotal = $price * $each_item['quantity'];
$cartTotal = $pricetotal + $cartTotal;
        $pricetotal = $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'] . '">  ';
// Create the product array variable
$product_id_array .= "$item_id-".$each_item['quantity'].","; 
// Dynamic table row assembly
$cartOutput .= '
<div style="width:46%;border:1px solid #99FFFF;background:#99FFFF;float:left;margin-top:10px;margin-left:9px;margin-right:5px;border-radius:10px;padding:5px;">
<div style="float:left;width:90%;font:bold 16px Arial;">' . $product_name . '</div>
<div style="float:left;width:5%;font:bold 16px Arial;float:right;">
<form action="cart.php" method="post"><input style="border:none;background:none;font-size:15px;" name="deleteBtn' . $item_id . '" type="submit" value="X" /><input name="index_to_remove" type="hidden" value="' . $i . '" /></form>
<h4 style="margin-top:5px;"><u>Purchase Details</u></h4>
<table style="margin-top:5px;width:90%;">
<td width="40%">Unit Price: </td>
<td>R' . $price . '</td>
<td width:60%;height:20px;border:1px solid black;>Quantity</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 . '" />

<td width:60%;height:20px;border:1px solid black;>Total</td>
<td>R' . $pricetotal . '</td>

    $cartTotal = $cartTotal;
     // Finish the Paypal Checkout Btn
$pp_checkout_btn .= '<input type="hidden" name="custom" value="' . $product_id_array . '">
<input type="hidden" name="notify_url" value="https://www.yoursite.com/storescripts/my_ipn.php">
<input type="hidden" name="return" value="https://www.yoursite.com/checkout_complete.php">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="cbt" value="Return to The Store">
<input type="hidden" name="cancel_return" value="https://www.yoursite.com/paypal_cancel.php">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="currency_code" value="USD">
<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - its fast, free and secure!">

This script obviously contains a paypal check out system so ignore it if it makes it easier..


Thanks in advance :D

Link to comment
Share on other sites

this is the same as your previous post called 'undefined Var Errors' and it seems you didn't even bother to try the things we suggested at the time.


for example, you're still doing this:

$sql = mysql_query("SELECT * FROM products WHERE id='$item_id' LIMIT 1");
while ($row = mysql_fetch_array($sql)) {

after I have explained to you that looping through results when you know there's only going to be one (LIMIT 1) is silly.

Edited by WebStyles
Link to comment
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.

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.