ollie007 Posted June 10, 2009 Share Posted June 10, 2009 $_POST[$type] is that how i write the variable or do i need ".$type." ? Link to comment https://forums.phpfreaks.com/topic/161644-how-to-write-this-_post-statement/ Share on other sites More sharing options...
FWDrew Posted June 10, 2009 Share Posted June 10, 2009 Assuming $type is defined somewhere, that should be fine. Link to comment https://forums.phpfreaks.com/topic/161644-how-to-write-this-_post-statement/#findComment-852931 Share on other sites More sharing options...
gevans Posted June 10, 2009 Share Posted June 10, 2009 You don't need the dollar sign. You are trying to access a $_POST value with the key of whatever is assigned to $type, which I'd imagine is nothing. $_POST['type']; Link to comment https://forums.phpfreaks.com/topic/161644-how-to-write-this-_post-statement/#findComment-852932 Share on other sites More sharing options...
ollie007 Posted June 10, 2009 Author Share Posted June 10, 2009 no, $type is a string, so do i need the $ sign? $type='name' $type='address' Link to comment https://forums.phpfreaks.com/topic/161644-how-to-write-this-_post-statement/#findComment-852933 Share on other sites More sharing options...
gevans Posted June 10, 2009 Share Posted June 10, 2009 In which case yes, you need the dollar sign. If $type is a string, and the string references one of the keys in $_POST it should work fine the way you originally posted. <?php //assuming name has been sent via post $type = 'name'; $name = $_POST[$type]; echo $name; If you are in a development environment and have errors on, you will see an error if the key does not exist. Link to comment https://forums.phpfreaks.com/topic/161644-how-to-write-this-_post-statement/#findComment-852934 Share on other sites More sharing options...
trq Posted June 10, 2009 Share Posted June 10, 2009 ollie, I seriously think you need to find a good book. Coming here an asking multiple simple questions will take you forever to learn what's going on. There's a good free book in my signature (Hudzilla) should get you started. Link to comment https://forums.phpfreaks.com/topic/161644-how-to-write-this-_post-statement/#findComment-852944 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.