I have this line in my PHP script:
$delivery = mysql_query("SELECT delivery_city FROM order_summaries WHERE order_number = '$_SESSION[CartNumber]'");
It works fine, but I believe that proper syntax would require a quote marks around the Session array key CartNumber. I am worried that someday, somewhere this line won't work because it does not have proper syntax.
I've tried escaping the various quote marks in this line, but that breaks the code.
Any suggestions?
Thanks!
MySQL Query Syntax Question
Moderator: General Moderators
- mydimension
- Moderator
- Posts: 531
- Joined: Tue Apr 23, 2002 6:00 pm
- Location: Lowell, MA USA
- Contact:
there are a few ways to do it. here is my favorite:
anything within the {} is considered a variable so you can quote the key name as usual.
Code: Select all
$delivery = mysql_query("SELECT delivery_city FROM order_summaries WHERE order_number = '{$_SESSIONї'CartNumber']}'");- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Within double quoted strings there is no need to quote your array elements so:
is just as valid syntactically as:
or
For more info:
http://www.php.net/manual/en/language.types.array.php
http://www.php.net/manual/en/language.t ... ng.parsing
Mac
Code: Select all
$sql = "SELECT delivery_city FROM order_summaries WHERE order_number = '$_SESSION[CartNumber]'";Code: Select all
$sql = "SELECT delivery_city FROM order_summaries WHERE order_number = '{$_SESSION['CartNumber']}'";Code: Select all
$sql = "SELECT delivery_city FROM order_summaries WHERE order_number = '".$_SESSION['CartNumber']."'";http://www.php.net/manual/en/language.types.array.php
http://www.php.net/manual/en/language.t ... ng.parsing
Mac
