JipThePeople Posted November 21, 2011 Share Posted November 21, 2011 I can successfully concatenate strings and vars to assemble a php var using an echo statement like this: echo "<input type='radio' id='radio_btn_" . $Row['question_number'] . "_0' name='question[question_" . $Row['question_number'] . "]' value='0' checked='checked' />"; However, when attempting to reference the same var in an IF statement, I can't seem to get the syntax right. I know this syntax is wrong, but I list it for reference to describe the issue I am trying to solve. if ($_POST['radio_btn_' . $Row['question_number'] . '_0'] == '0'){ I also tried curly braces but can't arrive at a solution. Any advise would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/251557-concatenation-with-strings-and-arrays/ Share on other sites More sharing options...
freelance84 Posted November 21, 2011 Share Posted November 21, 2011 $postToCheck = 'radio_btn_' . $Row['question_number'] . '_0'; if ($_POST[$postToCheck] == '0'){ Quote Link to comment https://forums.phpfreaks.com/topic/251557-concatenation-with-strings-and-arrays/#findComment-1290093 Share on other sites More sharing options...
JipThePeople Posted November 21, 2011 Author Share Posted November 21, 2011 $postToCheck = 'radio_btn_' . $Row['question_number'] . '_0'; if ($_POST[$postToCheck] == '0'){ That might be a great solution. I'll give it a shot. Thx. Quote Link to comment https://forums.phpfreaks.com/topic/251557-concatenation-with-strings-and-arrays/#findComment-1290135 Share on other sites More sharing options...
requinix Posted November 21, 2011 Share Posted November 21, 2011 Use the radio button's name, not its ID. $_POST['question_' . $Row['question_number']] Quote Link to comment https://forums.phpfreaks.com/topic/251557-concatenation-with-strings-and-arrays/#findComment-1290170 Share on other sites More sharing options...
JipThePeople Posted November 21, 2011 Author Share Posted November 21, 2011 Use the radio button's name, not its ID. $_POST['question_' . $Row['question_number']] Thx much! Quote Link to comment https://forums.phpfreaks.com/topic/251557-concatenation-with-strings-and-arrays/#findComment-1290188 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.