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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.