473,473 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

why is php so stupid?

4 New Member
ok, why is php so stupid?

why do i have to put double quotes inside the brackets here:

echo $_SESSION["PHPSESSID"];

but single quotes here:

$_SESSION['id'] = $row['FNAME'];

double quotes here:

echo "$sid";

and single quotes here:

mysql_query("INSERT INTO `current_session` (SID, ID) VALUES('$sid', '$id')") or die(mysql_error());


????????????
Apr 5 '11 #1
4 3748
Rabbit
12,516 Recognized Expert Moderator MVP
It shouldn't matter if you use double quotes or single quotes for the first two examples.

Double quotes are required for the third example because you want to expand the variable. Single quotes will not expand a variable and will instead treat the string as a literal. That way, you don't have to deal with the readability issues of escape characters.

For the last example, you could use single quotes but then you would have to escape the single quotes within the string because mysql requires single quotes.

So no, single quote or double quote doesn't matter as long as we're not talking about variable expansion. In the case of variable expansion, double quotes are necessary. But in every other case, it doesn't matter what you use as long as you escape the quotes you're using if they're within the string.
Apr 5 '11 #2
makai
4 New Member
literal?
escape?
variable expansion?

it seems i have a lot to learn.
Apr 5 '11 #3
Aimee Bailey
197 Recognized Expert New Member
Essentially what Rabbit was saying, was that there is not much different between single and double quotes. However each has it's own benefit.

As a starting rule, use single quotes when nothing fancy is going on between them. for instance:

Expand|Select|Wrap|Line Numbers
  1. echo 'hello, how are you today?';
  2.  
And double quotes when you want to do something that involves mixing the string with variables or escape characters. Like so:

Expand|Select|Wrap|Line Numbers
  1. $a = $_SESSION['name'];
  2. echo "Hello $a\n How are you today?";
  3.  
Note that \n is an escape character, this one in particular being an escape character that causes a line-break. Also, notice that I used singles instead of doubles for 'name', as nothing fancy was going on there.

Aimee.
Apr 6 '11 #4
code green
1,726 Recognized Expert Top Contributor
When you call PHP stupid - to what are you comparing?
Apr 6 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: sebb | last post by:
I'm kind of newbie to programming, but I thought of something and I want some opinions on that. It's about a new instruction block to do some cycles. I thought about that because it's not very...
119
by: rhat | last post by:
I heard that beta 2 now makes ASP.NET xhtml compliant. Can anyone shed some light on what this will change and it will break stuff as converting HTML to XHTML pages DO break things. see,...
2
by: Lampa Dario | last post by:
Hi, where is this stupid error in this program? When I execute it, i receive a segmentation fault error. #include <stdio.h> int main(int argc, char *argv, char *env) { int i=0; int l=0; int...
10
by: Fei Li | last post by:
Hi, If I'm not stupid for this, then the design of FolderBrowserDialog is very stupid. It only allow to strat browing from several predefined folder(Environment.SpecialFolder). What can I do if...
5
by: Guoqi Zheng | last post by:
I think I have this kind of problem very often, now it is really making me crazy. VS.NET always want to change my html code. Ok, that is fine as long as Vs.Net can ask my confirmaton first. For...
6
by: Adam Smith | last post by:
I have posted this and similar questions repeatedly and can't even raise a single response. I am being led to believe that this then 'Must be a stupid question' although people say that there is no...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.