carlg Posted May 24, 2007 Share Posted May 24, 2007 What is the proper php syntax for doing something like this $_POST['$row['myfield']'] $row was retreived using mysql_fetch_assoc Seems like I can't get the syntax right Thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/52807-syntax-question-variable-inside-of-_post/ Share on other sites More sharing options...
trq Posted May 24, 2007 Share Posted May 24, 2007 $_POST[$row['myfield']] Quote Link to comment https://forums.phpfreaks.com/topic/52807-syntax-question-variable-inside-of-_post/#findComment-260711 Share on other sites More sharing options...
carlg Posted May 24, 2007 Author Share Posted May 24, 2007 SWEET Thanks I always thought you needed those single quotes Quote Link to comment https://forums.phpfreaks.com/topic/52807-syntax-question-variable-inside-of-_post/#findComment-260719 Share on other sites More sharing options...
eric1235711 Posted May 24, 2007 Share Posted May 24, 2007 delimiting the $row['myfield'] with single quotes will not work as you want. Single quotes do not parse variable info. Use double quotes or without quotes: <?php // any one above will work: $_POST[$row['myfield']]; // with no quotes $_POST["{$row['myfield']}"]; // with double quotes and variable delimiter $_POST["$row[myfield]"]; // this also work but is not recommended ?> quotes are used to delimite strings. the double quotes let you put variables inside. the single quotes assumes the string "as it is"... back quotes is "another history". take a look in php doc at www.php.com about strings and array keys. Quote Link to comment https://forums.phpfreaks.com/topic/52807-syntax-question-variable-inside-of-_post/#findComment-260720 Share on other sites More sharing options...
trq Posted May 24, 2007 Share Posted May 24, 2007 Please... don't use double quotes unnecessarily. Quote Link to comment https://forums.phpfreaks.com/topic/52807-syntax-question-variable-inside-of-_post/#findComment-260721 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.