Jump to content

value of a radio button


bravo14

Recommended Posts

I am passing a radio button from a form $_POST['council']

 

if the radio button is selected I want the value set to 1 if not then it is set to 0, this will then dictate the charge that is set. The code I am using at the moment is

 


$council=0;
   if(isset($_POST['council'])){
       $council=1;
   }
   if($council=1){
       $charge='10';
   }
       else{
           $charge='2.50';
       }

 

However at the moment if the radio button is not selected the charge is still set to 10, if it is selected the charge is set to 10, what am I doing wrong?

Link to comment
https://forums.phpfreaks.com/topic/272973-value-of-a-radio-button/
Share on other sites

You are using an assignment operator in your if ( = ) and not the conditional one ( == ).

 

Change that and it should work properly. 

 

$council=0;
        if(isset($_POST['council'])){
                $council=1;
        }
        if($council == 1){
                $charge='10';
        }
                else{
                        $charge='2.50';
                }

You are using the assignment operator '=' instead of the comparison operator '==' in the second if statement, therefore the if statement interprets the 1 as a TRUE value and will always execute the if statement.

 

Just change the second if to ==.

 

Kind regards,

 

L2c

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.