PHP Mini Shopping Cart

Hi guys,

I follow the instructions for mini shopping cart on YouTube (“http://www.youtube.com/watch?v=Jzzv6W_VrUM”) and got everything working except for the last function “function paypal_items()”. PHP reports me the error:
“Parse error: syntax error, unexpected ‘;’ in C:\wamp\www\PROJECTS\MINI_SHOPPING_CART\cart.php on line 100”

That would be the following line of code: “$get = mysql_query('SELECT…”

Could anybody help me out with this?

Thanks.

Amel

function paypal_items(){

	$num = 0;
	
	foreach($_SESSION as $name => $value){
	
		if($value!=0){
		
			if(substr($name, 0, 5)=='cart_'){
			
				$id = substr($name, 5, strlen($name)-5);
				
				$get = mysql_query('SELECT id, name, price, shipping FROM products WHERE id='.mysql_real_escape_string((int)$id);
				
				while($get_row = mysql_fetch_assoc($get)){
					
					$num++;
					
					echo '<input type="hidden" name="item_number_'.$num.'" value="'.id.'">';
					
					echo '<input type="hidden" name="item_name_'.$num.'" value="'$get_row['name'].'">';
					
					echo '<input type="hidden" name="amount_'.$num.'" value="'$get_row['price'].'">';
					
					echo '<input type="hidden" name="shipping_'.$num.'" value="'$get_row['shipping'].'">';
					
					echo '<input type="hidden" name="shipping2_'.$num.'" value="'$get_row['shipping'].'">';
					
					echo '<input type="hidden" name="quantity'.$num.'" value="'.$value.'">';
				
				}
				
			}
		
		}
	
	}
	
}

$get = mysql_query('SELECT id, name, price, shipping FROM products WHERE id='.mysql_real_escape_string((int)$id);

You’re missing a closing ) in this line.

But if you cast $id with int(), there’s no need for mysql_real_escape_string anymore.

So that line could become:


$get = mysql_query('
  SELECT id, name, price, shipping 
  FROM products 
  WHERE id = ' . (int)$id
);

Hi Guido, thank you for reply. I realized that soon after I posted the question. Also, I forgot $ in front of id and didn’t concatenate the variables later in the code.

I guess I was to eager to get the thing working and kept forgeting stuff.

Thanks.

Amel