tommr Posted December 28, 2010 Share Posted December 28, 2010 Would someone please take a look at this. I am trying to use a form to allow users to answer yes or no with radio buttons, and then print it out on another page. I can only get the script to print the number 1 no matter which button is selected. When I check the database the number 1 is recorded no matter which button is selected. In the top of the input form I have <input type='hidden' name='electricity' value='0'> In the body of the input form I have Electricity <input type='radio' name='electricity' value='0'>no <input type='radio' name='electricity' value='1'>yes And on the output page I have $electricity = $row['electricity']; if ($electricity == 1) { $answer = "YES"; } else { $answer = "NO"; } and echo $row['electricity']; I have been over and over this and can not discover my error. Thank you for looking. Link to comment https://forums.phpfreaks.com/topic/222772-converting-0-1-2-to-yes-no/ Share on other sites More sharing options...
PHPTOM Posted December 28, 2010 Share Posted December 28, 2010 Where is the $row array coming from? Do you mean $_POST? Why do you have 2 inputs with the same name (hidden and radio)? Also you should have "1" instead of 1 as it is a string. A simpler way would be $answer = ($_POST['electricity'] == "1") ? "YES" : "NO"; Link to comment https://forums.phpfreaks.com/topic/222772-converting-0-1-2-to-yes-no/#findComment-1151980 Share on other sites More sharing options...
tommr Posted December 28, 2010 Author Share Posted December 28, 2010 Where is the $row array coming from? Do you mean $_POST? The $row array is from the form that prints the output from the script. echo "<td class='det-B'>Electricity</td><td class='det-B'>"; echo $row['electricity']; echo "</td></tr>"; echo "<tr>"; Why do you have 2 inputs with the same name (hidden and radio)? I didn't design the form. I don't know why they are there. Link to comment https://forums.phpfreaks.com/topic/222772-converting-0-1-2-to-yes-no/#findComment-1151991 Share on other sites More sharing options...
PHPTOM Posted December 28, 2010 Share Posted December 28, 2010 Please give us the full picture, because so far you have only gave us bits. Link to comment https://forums.phpfreaks.com/topic/222772-converting-0-1-2-to-yes-no/#findComment-1151992 Share on other sites More sharing options...
tommr Posted December 28, 2010 Author Share Posted December 28, 2010 I took a antihistamine for hives and it made me extra stoopid. I forgot to echo $answer thanks for taking the time. Link to comment https://forums.phpfreaks.com/topic/222772-converting-0-1-2-to-yes-no/#findComment-1151994 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.