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. 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'){ 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. 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']] 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! 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
Archived
This topic is now archived and is closed to further replies.