Re: value passing from html form to php variable.

From: Date: Sat, 01 Jun 2002 16:06:12 +0000
Subject: Re: value passing from html form to php variable.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-100234@lists.php.net to get a copy of this message
> $query = "INSERT INTO friends (id, firstname, surname) values > (nextval('friends_id_seq'), > $_POST['firstname'], $_POST['surname'])"; > > which returns error: > Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or > T_VARIABLE or T_NUM_STRING in > /local/scratch-1/ww220/Apache1.3/htdocs/test/add2.php on line 5 When using arrays in strings, things are done a little differently: print "a $arr[key] string"; print "a {$arr['key']} string"; print "a " . $arr['key'] . " string"; Be sure to always surround keys with quotes outside of strings otherwise PHP looks for a CONSTANT named key first, instead. define ('a','b'); $arr = array('a' => 'apple', 'b' => 'banana'); print $arr[a]; // banana print "$arr[a]"; // apple print $arr['a']; // apple Regards, Philip Olson

« previous php.general (#100234) next »