Jump to content

php-mysql


tayhaithian

Recommended Posts

i need some help on 'adding cart'... it seems to be have some problem with session that it wont add new value if the SESSION exist and it just acumulate +1 rather than array ++; .

Thx for advance help.

 

 

<html>

<body>
<?php 
include('conn.php');

if(isset($_POST['Submitted']))
{
session_start();
$food_id = (int) $_GET['food_id'];
$price = $_POST['price'];
$quant = $_POST['quant'];


if(isset($_SESSION['cart'][$food_id]))
{

	$_SESSION['cart'][$food_id]['quantity']++;
	print_r($_SESSION['cart'][$food_id]);

	echo '<p>Another copy of the print has added </p>';
}else{

	require_once('conn.php');


	$_SESSION['cart'][$food_id]=
	array('quantity' => $quant, 'price' => $price);

	echo '<p>The print has been added to your shopping cart.</p>';
	print_r($_SESSION['cart'][$food_id]);

	}

	mysql_close($conn);

	}





include('conn.php');

$query= "select * from foods";

$result= mysql_query($query);



while( $row=mysql_fetch_array($result))
{
echo '<form method="POST" action="test.php?food_id=',$row["food_id"],'">';
echo '<table border="0" cellspacing="5">';
echo '<tr><td>',$row["name"],'</td></tr>',
'<tr><td rowspan="2"><img src="',$row["image"],'" width="200px" height="200px" /></td>',
'<td>',$row["description"],'</td></tr>',
'<tr><td><input type="radio" name="price" value="';
echo $row["price_reg"];
echo '" />','RM',$row["price_reg"],' ',
'<input type="radio" name="price" value="';
echo $row["price_large"]; 
echo '" />','RM',$row["price_large"],'<br />',
'Quantity:','<input type="text" name="quant" size="1"/>','</td>';
echo '<td><input type="submit" name="ADD" value="ADD" /></td></tr>';
echo '<input type="hidden" name="Submitted" value="TRUE" />';
echo '<br />',$row["food_id"];
echo '</table>';	
echo '</form>';	



}



?>




</body>
</html> 

Link to comment
Share on other sites

hold on i think i get where the wrong adi , but dunno how to exchange the quantity instead on just adding another new line of array++ .

 

 

any idea to modify the quantity instead of array++ ?

 

 

 

$_SESSION['cart'][$food_id]

Array ( [quantity] => 47 [price] => 19.88 )

 

if

$_SESSION['cart'][$food_id]['quantity'] 

it just apear quantity number

47

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.

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.