简体   繁体   中英

Radio Buttons to PHP-MySQL

How can I get the value of a radio button like a "Gender Selector" (Male/Female) to PHP? I really need it for my register.php form. I tried googling it but they didnt provide how to get the value of it just how to generate it.

Code

<form action = "register.php" method = "post">
<input type="radio" name="sex" value="male">Male<br>
<input type="radio" name="sex" value="female">Female
</form>

PHP:

$sex = $_POST['radiobutton=sex'];

Your form needs a submit button. When you hit submit, on your register.php , you can do

$sex = $_POST['sex']

What you put in the brackets is what you specify in the name attribute for your radio buttons.

Seriously though... you should try to understand the basics of forms in general. Here's a decent tutorial

On the page with form:

<form action='register.php' method='POST'>
    <input type='radio' name='sex' value='male'/>Male
    <input type='radio' name='sex' value='female'/>Female
    <input type='submit' name='submit_sex' />
</form>

On register.php:

<?php

if (isset($_POST['submit_sex']))
    echo 'Gender is ' . $_POST['sex'];

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM