Jump to content

Shopping Cart Checkout?


Flezria

Recommended Posts

Hi guys!

 

I'm new here, and i have a quick question:

 

I'm building a shopping cart, for a website, everything works fine, but i have a problem when i wanna do the checkout:

 

The checkout is supposed to take all the products from the basket, and add them into an email, which will be sent to order-guy.

 

Those lines:

 

 

$message="Navn: $name \nTelefon nummer: $phone \nGruppe nummer: $grpnr \nAfdeling: $afdeling \n\n " .
foreach ($_SESSION['contents'] as $_SESSION['id']=>$_SESSION['qty']) {
$sql = "SELECT * FROM entries WHERE id = '$_SESSION[id]'";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
"Produktnavn: $row[1]\n
IRIS: $row[6]\n";
}

 

Gives me the error: syntax error, unexpected T_FOREACH

 

Anyone can help me with this?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/269978-shopping-cart-checkout/
Share on other sites

You have to end the first line or add some more code...

 

$message="Navn: $name \nTelefon nummer: $phone \nGruppe nummer: $grpnr \nAfdeling: $afdeling \n\n " ;
foreach ($_SESSION['contents'] as $_SESSION['id']=>$_SESSION['qty']) {
$sql = "SELECT * FROM entries WHERE id = '$_SESSION[id]'";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
"Produktnavn: $row[1]\n
IRIS: $row[6]\n";
}

You can only concatenate values - literal strings, variables/properties, constants, return values from functions/methods, expressions...

 

You would need to concatenate the new information you are retrieving inside of the loop onto the end of the $message string.

 

Also, you should not be executing a query inside of a loop. You should get an array of the id values, concatenate those ids into a list and execuiting ONE query using an IN() comparison - http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#function_in You would then loop over the result set from that one query.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.