MYSQL statement doubt $ SQL = "select * from news where id = '". $ _ GET ['id']. "'";
$ Query = mysql_query ($ SQL );
$ Rs = mysql_fetch_array ($ query );
Why is an error occurred when writing the preceding query statement? $ SQL = "select * from news where id = $ _ GET ['id']";
Thank you for your understanding of the difference between single quotes and double quotes!
Reply to discussion (solution)
You can add {}
$ SQL = "select * from news where id = {$ _ GET ['id']}";
$ SQL = "select * from news where id = $ _ GET ['id']";
This should be correct. what error is prompted ??
You can add {}
$ SQL = "select * from news where id = {$ _ GET ['id']}";
Can you explain it? Why not?
$ SQL = "select * from news where id = $ _ GET ['id']";
This should be correct. what error is prompted ??
Error: Parse error: syntax error, unexpected ''(T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C: \ Program Files \ Apache Software Foundation \ Apache2.2 \ htdocs \ just \ edit. php on line 5
This is a php convention. why?
When a member of an associated array appears in double quotes, you must write
"$ _ GET [id]"
Or
"{$ _ GET ['id']}"
This is a php convention. why?
When a member of an associated array appears in double quotes, you must write
"$ _ GET [id]"
Or
"{$ _ GET ['id']}"
Well, no error will be reported for either of your two formats.
$ Nc =$ _ POST [nc];
$ SQL = mysql_query ("select * from tb_user where name = '". $ nc. "'", $ conn );
$ Nc is a common variable that accepts the value assigned by $ _ POST [nc]. why do you want to write it like this? "select * from tb_user where name = '". $ nc. "'"
Echo $ SQL; everything is clear
Why do you want to write this statement like this? "select * from tb_user where name = '". $ nc ."'"
That's because he doesn't know or is used to his original language.
Of course, it may be because you have listened to others' misleading ideas.
"Select * from tb_user where name = '$ nc '"
Low efficiency due to addressing
As everyone knows, "select * from tb_user where name = '". $ nc ."'"
Is there an addressing process?
Oh, I thought it was fixed like that. This PHP single double quotation mark is mixed with C and C ++. String and a single character. Thank you!