bravo14 Posted January 10, 2013 Share Posted January 10, 2013 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 More sharing options...
premiso Posted January 10, 2013 Share Posted January 10, 2013 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'; } Link to comment https://forums.phpfreaks.com/topic/272973-value-of-a-radio-button/#findComment-1404791 Share on other sites More sharing options...
Love2c0de Posted January 10, 2013 Share Posted January 10, 2013 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 Link to comment https://forums.phpfreaks.com/topic/272973-value-of-a-radio-button/#findComment-1404793 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.