I am facing a problem of arrays.The fact is that I am getting the array values but when i am running 2 arrays under a single for loop then I am only getting null values for the quantities....lets give you the code so that you can understand where the problem lies.
As you see I am not getting the net_total and quantity
PHP Code:
//if the form is submitted
if(isset($_POST['image1_x']))
{
$pid=$_POST['pid'];//product id
$quantity=$_POST['quantity'];
$item_price=$_POST['item_price'];
if($pid!="")
{
for(
;
list($key1, $value1 ) = each( $pid ) ,
list($key2, $value2 ) = each( $quantity )
;
) {
echo "Key1: $key1; Value1: $value1<br />\n";
echo "Key2: $key2; Value2: $value2<br />\n";
foreach($item_price as $k=>$v)
{
list($v1,$v2)=explode("#",$v);//(price and pid)
if($value1!="")
{
if($v2==$value1)//if pid==pid
{
$net_total=$value2*$v1;
$s_pro="select pid from temp_cart where pid='$value1' and cart_id='$cart_id'";// TO SEE IF THE SELECTED PRODUCT IS ALREADY IN THE CART OR NOT
$q_pro=mysql_query($s_pro) or die(mysql_error());
$numrows=mysql_num_rows($q_pro); if($numrows=="")
{
//echo "insert into temp_cart(cart_id,pid,quantity,item_price,net_total) values('$cart_id','$value1','$value2','$v1','$net_total')";
$s_temp="insert into temp_cart(cart_id,pid,quantity,item_price,net_total) values('$cart_id','$value1','$value2','$v1','$net_total')";
$q_temp=mysql_query($s_temp) or die(mysql_error());
header("location:cart.php");
}
else
{
$err=1;//one of the selected product is already in the cart
}
}
}
}
}
}
else
{
$emp=1;//no product has been selected
}
}
Bookmarks