Flezria Posted October 27, 2012 Share Posted October 27, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/269978-shopping-cart-checkout/ Share on other sites More sharing options...
Jessica Posted October 27, 2012 Share Posted October 27, 2012 Look at the last character on the line before your foreach. Quote Link to comment https://forums.phpfreaks.com/topic/269978-shopping-cart-checkout/#findComment-1388130 Share on other sites More sharing options...
fesan Posted October 27, 2012 Share Posted October 27, 2012 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"; } Quote Link to comment https://forums.phpfreaks.com/topic/269978-shopping-cart-checkout/#findComment-1388131 Share on other sites More sharing options...
PFMaBiSmAd Posted October 27, 2012 Share Posted October 27, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/269978-shopping-cart-checkout/#findComment-1388136 Share on other sites More sharing options...
Flezria Posted October 27, 2012 Author Share Posted October 27, 2012 Thanks for all the replies! I will try to make it work, thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/269978-shopping-cart-checkout/#findComment-1388155 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.