Re: $_POST in MySQL query issue...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The reason curly braces are needed are because you are putting an array 
element into a string. Consider..

$sBlah = 'blah';
echo "$sBlahfoo$sBlahfoo";

PHP will attempt to echo the variable $sBlahfoo twice. if you use

echo "{$sBlah}foo{$sBlah}foo";

you have told php explicitly when to look for variable substitution. so the 
result will be 

blahfooblahfoo

PHP will not look for array elements to substitute in strings, unless you 
explicitly tell it to by using curly braces. 

$aBlah['blah'] = 'foo';
echo "$aBlah['blah']";
result Parse Error

echo "{$aBlah['blah']}";
result :
foo

Once again, try the manual for more information

http://php.net/manual/en/language.types.string.php

Hope this helps


Lang




Adam Reiswig wrote:

> A couple of days ago I placed a post regarding using the $_POST[]
> variable in an insert sql query.  Both
> 
> $sql="insert into $table set Name = '".$_POST['elementName']."'";
>    and
> $sql="insert into $table set Name = '{$_POST['elementName']}'";
> 
> worked perfectly.  Thanks to everyone for your help.  My question now is
> regarding the curly brackets in the 2nd example.  Can anyone describe
> why using the curly brackets works and/or how php processes them.  I
> have read quite a bit about php and never come accross thier use in this
> way.  Thanks again.
> 
> -Adam Reiswig

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux