472,354 Members | 2,238 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

why is php so stupid?

4
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 3707
Rabbit
12,516 Expert Mod 8TB
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
literal?
escape?
variable expansion?

it seems i have a lot to learn.
Apr 5 '11 #3
Aimee Bailey
197 Expert 100+
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 Expert 1GB
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made but the http to https rule only works for...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

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.