Jump to content

converting 0 - 1 - 2 to yes no


tommr

Recommended Posts

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

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";

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.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.