so I have a php function that makes a radio button and I call that function twice to create 2 radio buttons. The different values are Regular and High Quality. My question is how do I get the value of which radio button is selected. I have attached some of my code. The first snippet is my function to create my radio button.
function create_paint_radio($value){
echo'<input type="radio" name="paintType" value="' . $value . '"';
echo " /> $value ";
}
Next I have the code to create the buttons
create_paint_radio('Reagular');
create_paint_radio('High Quality');
Next, I have the code that I am trying to use to check if the one of the radio buttons is selected.
if(!empty($_POST['paintType'])){
$paintType = $_POST['paintType'];
}else{
$paintType = NULL;
echo '<p class = "error">Please select a paint type.<br></p>';
}
Lastly, I have the code that Im using to try and access the value. I need the value to make a calculation. So for instance, if the value = 'Regular' then the cost of the paint is $1.75 and if it is 'High Quality' then it is $2.50.
if($name && $email && $zip && $city && $state && $roomLength && $roomWidth && $paintType){
echo 'Cost of Paint Job is approximate $' . calculate($roomLength, $roomWidth, $paintType);
}
function calculate($length, $width, $paint){
$roomSize = (2*($length * 8)) + (2*($width * 8)) + ($length * $width);
if($paint == 'Regular'){
$paintCost = 1.75;
}else{
$paintCost = 2.50;
}
$estimate = ($roomSize * $paintCost) * .80;
return $estimate;
}
So the problem is that I am not getting the correct value in the calculate function from the radio buttons so the paintCost is always being set to $2.50 because of the else statement. Is there another way to access the value of the radio buttons to check against. Sorry I am new to php. I hope I provided enough info on the problem. Thank you.