RE: [PHP] quick question

From: Date: Fri, 11 Jan 2002 11:05:27 +0000
Subject: RE: [PHP] quick question
Groups: php.general 
Request: Send a blank email to php-general+get-80185@lists.php.net to get a copy of this message
> -----Original Message----- > From: Erik Price [mailto:pricee@hhbrown.com] > Sent: 10 January 2002 15:44 > > I thought that $_GET[] and $_POST[] could be used in place of regular > variables... that is, > > $sql = "SELECT * FROM tablename WHERE > tablename.column=$_GET['criteria_integer']"; > > but unfortunately, this isn't working. No, of course not -- I repeat: > On Thursday, January 10, 2002, at 08:18 AM, Ford, Mike [LSS] wrote: > > > But, if you insist on the quotes, it needs to be: > > > > case "{$_POST['insert']}" > > > > to ensure that the array index gets processed properly. Please note the {}, which you *MUST* include to get the array index processed properly. If you write: "$_POST['insert']" PHP will try to interpret this as the variable called $_POST followed by the string "['insert']", which is clearly not what you want. including the {} forces it to use the value of $_POST['insert'], which *is* what you want. Incidentally, I've occasionally had problems including a variable name containing an underscore in a double-quoted string (e.g. "$num_recs records retrieved"), where PHP tries to insert the value of $num followed by the string "_recs", so I always {} those as well, just to be on the safe side ("{$num_recs} ..." or "${num_recs} ..." both work. Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: m.ford@lmu.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.general (#80185) next »