darp Posted February 8, 2011 Share Posted February 8, 2011 In this link quotes withing a global session array are clarified http://www.phpfreaks.com/forums/mysql-help/%28solved%29-confused-as-to-what-quote-mark-to-use-in-a-query/ However I can't get $_SESSION['cid'] to work. Could someone explain to me why this works: $mysql = "UPDATE customer SET menulist = ' $menulist ', packlist = ' $packlist ' WHERE customer ='$_SESSION[cid]'"; mysql_query($mysql); Where as this does not. $mysql = "UPDATE customer SET menulist = ' $menulist ', packlist = ' $packlist ' WHERE customer =" . $_SESSION['cid']; mysql_query($mysql); What would the proper syntax/format be? Quote Link to comment https://forums.phpfreaks.com/topic/227027-in-a-query-why-does-_sessioncid-work-but-_sessioncid-not-work/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 8, 2011 Share Posted February 8, 2011 The php parser needs a little help delimiting array variables when used in a string. If you put {} around $_SESSION['cid'] it will work without producing an error inside of a string. Quote Link to comment https://forums.phpfreaks.com/topic/227027-in-a-query-why-does-_sessioncid-work-but-_sessioncid-not-work/#findComment-1171313 Share on other sites More sharing options...
darp Posted February 8, 2011 Author Share Posted February 8, 2011 Thanks for the fast reply. This works. Do I have it right or can I improve on it? $mysql = "UPDATE customer SET menulist = ' $menulist ', packlist = ' $packlist ' WHERE customer = '{$_SESSION['cid']}'"; mysql_query($mysql); Quote Link to comment https://forums.phpfreaks.com/topic/227027-in-a-query-why-does-_sessioncid-work-but-_sessioncid-not-work/#findComment-1171319 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.