Click to See Complete Forum and Search --> : PHP Shopping cart problem (it is not working on few computers)


ymsweb
February 22nd, 2011, 12:14 AM
Hi all,

We are having problems in the shopping cart created. It says "Shopping cart" is empty some pc's but on some pc's it is functioning properly. The shopping cart is working from my side but from client side (on client's pc's) it is some pc's working and some pc's not.

Here under I am giving the complete code that is functioning when clicking on the add to cart button. Can someone assist me better and tel me what actually is the problem inside the code.

I thanks to all of you.

Regds,
Yogendra

<?php include("admin/includes/session.php"); ?>
<?php include("checkextension.php"); ?>
<?php include("checkhttp.php"); ?>
<?php include("admin/includes/connection.php"); ?>
<?php
/*
$invoiceQuery="select max(invoice_no) as invoice_no from cart";
$invoiceQueryresult=mysql_query($invoiceQuery);
$row=mysql_fetch_array($invoiceQueryresult);
$invoice_no=$row['invoice_no']+1;
$updtQuery="update cart set invoice_no='".$invoice_no."' where rand_value='".$randnum."'";

*/
$session_id=session_id();
$today=date("Y-n-j H:i:s");
$ip_address=$_SERVER['REMOTE_ADDR'];
$rand_number=rand()."".rand()."".rand(5, 1000);
//echo $rand_number;
//know invoice number
$invoiceQuery="select * from cart";
$invoiceQueryresult=mysql_query($invoiceQuery);
$num=mysql_num_rows($invoiceQueryresult);
if($num ==0)
{$invoice_no="1000";}
else
{
$invoice_no="0";
}
////////////////////
$product_id=@array_values($_POST['product_id']);
if ((count($product_id)>0))
{
$product_id=@implode(',',@array_values($_POST['product_id']));
}
$recommended_quantity=@array_values($_POST['recommended_quantity']);
if ((count($recommended_quantity)>0))
{
$recommended_quantity=@implode(',',@array_values($_POST['recommended_quantity']));
}
//echo "<br><br><br>Product IDs: ".$product_id."<br><br>";
//echo "Product Qtys: ".$recommended_quantity."<br><br>";
///// fetching the user email /////
$result_user = mysql_query("select * from customers where email = '".$_SESSION['myusername']."'");
while($row_user = mysql_fetch_array($result_user))
{
$user_id=$row_user['id'];
$user_country_id=$row_user['country'];
}
///////////////
?>
<?php
/////////////// Adding main product not recommended products ////////////////////
$pid=$_POST['pid'];
$product_color=$_POST['product_color'];
$measurement_size=$_POST['measurement_size'];
$quantity=$_POST['quantity'];
$result = mysql_query("SELECT * FROM product where id = ".$pid."");
while($row = mysql_fetch_array($result))
{
$unit_price=$row['unit_price'];
$special_price=$row['special_price'];
$discount_price=$row['discount_price'];
if($special_price!=0.00)
{
$product_price=$special_price;
}
elseif($discount_price!=0.00)
{
$product_price=$discount_price;
}
else
{
$product_price=$unit_price;
}
$weight=$row['product_weight1'];
$total_weight=$weight*$quantity;
$total_price=$product_price*$quantity;
}
$sql="insert into cart(user_id, product_id, unit_price, qty, weight, totalweight, product_color, measurement_size, subtotal, sess_id, ip_address, payment_status, rand_value, login_chk, invoice_no, is_wishlist, modified, created)VALUES('".$user_id."', '".$pid."', '".$product_price."', '".$quantity."', '".$weight."', '".$total_weight."', '".$product_color."', '".$measurement_size."', '".$total_price."', '".$session_id."', '".$ip_address."', '0', '".$rand_number."', '', '".$invoice_no."', 'No', '".$today."', '".$today."')";
$result=mysql_query($sql);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

$productArray = explode(",", $product_id);
$qtyArray = explode(",", $recommended_quantity);
$i = 0;
foreach($productArray as $productid)
{
$result = mysql_query("SELECT * FROM product where id = ".$productid."");

while($row = mysql_fetch_array($result))
{
$unit_price=$row['unit_price'];
$special_price=$row['special_price'];
$discount_price=$row['discount_price'];
if($special_price!=0.00)
{
$product_price=$special_price;
}
elseif($discount_price!=0.00)
{
$product_price=$discount_price;
}
else
{
$product_price=$unit_price;
}

$weight=$row['product_weight1'];
$total_weight=$weight*$qtyArray[$i];
$total_price=$product_price*$qtyArray[$i];
}

if($qtyArray[$i] != 0)
{
$sql="insert into cart(user_id, product_id, unit_price, qty, weight, totalweight, subtotal, sess_id, ip_address, payment_status, rand_value, login_chk, invoice_no, is_wishlist, modified, created)VALUES('".$user_id."', '".$productid."', '".$product_price."', '".$qtyArray[$i]."', '".$weight."', '".$total_weight."', '".$total_price."', '".$session_id."', '".$ip_address."', '0', '".$rand_number."', '', '".$invoice_no."', 'No', '".$today."', '".$today."')";
$result=mysql_query($sql);
//echo "Name " . $nameArray[$i] . " shoud correspond with Email " . $email . "<br>";
}
else
{
echo "";
}

$i++;
}
header("location:shopping-cart");
?>

PeejAvery
February 22nd, 2011, 06:19 AM
First off, PHP is a server-side scripting language. It is never seen by the client-side at all. So, if your having a problem on various computers, then it's not PHP.

Second, did you write this software yourself? If not, then it's best to contact the author, not us. He/she already knows the code. We, on the other hand, do this in our free time and would have spend time getting to know the code before even helping you.

EDIT: Also, note that if you purchased this code, then you are most likely in violation of its purchase agreement. If you are, you need to remove the code from the original post.