Bug #15673 Updated: Quotes crash MySQL queries: $array['val'] = Parse Error, but $array[val] works
| From: | jpaulomf at terra dot com dot br | Date: | Fri, 22 Feb 2002 12:25:35 +0000 |
| Subject: | Bug #15673 Updated: Quotes crash MySQL queries: $array['val'] = Parse Error, but $array[val] works | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-809@lists.php.net to get a copy of this message | ||
ID: 15673
Updated by: jpaulomf@terra.com.br
-Summary: Quotes crash MySQL queries: $array['val'] = Parse
Error, but $array[val] works
Reported By: jpaulomf@terra.com.br
Status: Analyzed
Bug Type: Arrays related
Operating System: Linux 2.4.5
PHP Version: 4.1.1
New Comment:
Hey man WOW, Im impressed, you have already replied!!!
Yes, this solution works:
$query = "SELECT * from {$table['users']}";
But shouldn't "Blah $table['users']" work as well?
Shouldn't PHP at least send a warning when using "$table[users]" even
if the other "$arr['foo']" syntaxes where wrong?
Thanks!
Previous Comments:
------------------------------------------------------------------------
[2002-02-22 07:17:21] mfischer@php.net
Use the {$array['key']} syntax as I told you.
However, I can't remember if "foo $array['bar']" ever worked or not
right now. Someone else?
------------------------------------------------------------------------
[2002-02-22 07:12:54] jpaulomf@terra.com.br
It seems we cannot use the correct syntax $table['users'] inside the
two ""...
This will work:
$result = mysql_query("SELECT * from ".$table['users']);
This wont work:
$result = mysql_query("SELECT * from $table['users']");
This will, but should send a warning and it isnt:
$result = mysql_query("SELECT * from $table[users]");
The errors happens everywere I call any array with the '' or "" like
$table["something"] or $table['something'] inside ""s...
------------------------------------------------------------------------
[2002-02-22 07:06:12] jpaulomf@terra.com.br
Sorry: The error occurs when we define the $query:
$query = "SELECT * from $table[users]"; // => This causes the parse
error
echo "Table $table['users']" //=> Parse Error too
echo "Table".$table['users']; //=>OK
$query = "SELECT * from ".$table['users']; //=> OK TOO
------------------------------------------------------------------------
[2002-02-22 06:59:46] jpaulomf@terra.com.br
d
------------------------------------------------------------------------
[2002-02-22 06:55:12] mfischer@php.net
Sounds very strange. Can you do a var_dump() on the sql string?
Can you also test and report back if it works with
"SELECT * from {$table['users']}"
?
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/15673
--
Edit this bug report at http://bugs.php.net/?id=15673&edit=1