Re: PHP error parsing SQL string containing assoc. array
| From: | Frank M. Kromann | Date: | Sat, 24 Mar 2001 04:25:37 +0000 |
| Subject: | Re: PHP error parsing SQL string containing assoc. array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-45409@lists.php.net to get a copy of this message | ||
Hi All,
PHP is unable to resolve the variable you are trying to use within a stting. If you use complex
array structures you have to write it like this:
$sql = "insert into sessions(session_id, user_id, session_expiration) values
('$sess_id', " . $user_fields['USER_ID'] . "', sysdate + ("
. $user_fields'MINS_TILL_EXPIRE'] . " * 1/1440))";
or use
$sql = sprintf("insert into sessions(session_id, user_id, session_expiration) values
('%s', sysdate + (%i * 1/1440))", $sess_id', $user_fields['USER_ID'],
$user_fields['MINS_TILL_EXPIRE']);
Your sample code also mised a ' after the first variable !
- Frank
> I'm trying to write a sql statement (for Oracle) that uses an associative
> array element as a dynamic value. PHP is choking on this line:
>
> $sql = "insert into sessions(session_id, user_id, session_expiration) values
> ('$sess_id', $user_fields['USER_ID'], sysdate +
> ($user_fields['MINS_TILL_EXPIRE'] * 1/1440))"
>
> I get this error back from PHP:
>
> Parse error: parse error, expecting
T_STRING' or
> T_VARIABLE' or `T_NUM_STRING'
>
> Can I not use my associative array like this?
>
> --
> Michael Champagne, Software Engineer
> Capital Institutional Services, Inc.
> wk: mchampagne@capis.com
> hm: mchamp@texas.net
>
>
>
> ******************************************************************
> This communication is for informational purposes only. It is not
> intended as an offer or solicitation for the purchase or sale of
> any financial instrument or as an official confirmation of any
> transaction, unless specifically agreed otherwise. All market
> prices, data and other information are not warranted as to
> completeness or accuracy and are subject to change without
> notice. Any comments or statements made herein do not
> necessarily reflect the views or opinions of Capital Institutional
> Services, Inc. Capital Institutional Services, Inc. accepts no
> liability for any errors or omissions arising as a result of
> transmission. Use of this communication by other than intended
> recipients is prohibited.
> ******************************************************************
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>
>