Jump to content

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';
                }

Edited by premiso

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

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.