Jump to content

Radio buttons have to be selected, and therefore they will always have a value.

$answer = $_POST['radio_button'];
This code above will assign the value of whichever selected radio button to the variable answer.

15" MBP TB

AMD 5800X | Gigabyte Aorus Master | EVGA 2060 KO Ultra | Define 7 || Blade Server: Intel 3570k | GD65 | Corsair C70 | 13TB

Link to post
Share on other sites

if you thought about if(!isset($_POST['mycheckbox'])) its not gonna work since the value is 0

I don't understand your question?

15" MBP TB

AMD 5800X | Gigabyte Aorus Master | EVGA 2060 KO Ultra | Define 7 || Blade Server: Intel 3570k | GD65 | Corsair C70 | 13TB

Link to post
Share on other sites

i want to make sure a radio button is selected in php

In your example you used $_POST['mycheckbox'], so are you talking about radio buttons or check boxes?

15" MBP TB

AMD 5800X | Gigabyte Aorus Master | EVGA 2060 KO Ultra | Define 7 || Blade Server: Intel 3570k | GD65 | Corsair C70 | 13TB

Link to post
Share on other sites

i dont want my radio button to be selected by default...

 

Then you shouldn't be using radio buttons. Radio buttons are to allow a user to select from a range of options but require them to select one.

 

Sounds like you should be using checkboxes.

Link to post
Share on other sites

i want to make sure a radio button is selected in php

 

What about this? My example below incorporates sessions, but the basic idea is just using if (!isset($poop): ...blah blah.

 

<?phpsession_start();if (!isset($_POST['radio'])):    $_SESSION['result'] = "You didn't choose a Radio Button..";else:    $_SESSION['result'] = $_POST['radio'];endif;header('Location: index.php');?>
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×