简体   繁体   English

PHP-MySQL的单选按钮

[英]Radio Buttons to PHP-MySQL

How can I get the value of a radio button like a "Gender Selector" (Male/Female) to PHP? 如何获得PHP等“性别选择器”(男/女)单选按钮的值? I really need it for my register.php form. 我的register.php表单确实需要它。 I tried googling it but they didnt provide how to get the value of it just how to generate it. 我尝试使用Google搜索,但他们没有提供如何获取其价值以及如何生成它。

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: PHP:

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

Your form needs a submit button. 您的表单需要一个提交按钮。 When you hit submit, on your register.php , you can do 当您点击Submit时,可以在register.php上执行

$sex = $_POST['sex']

What you put in the brackets is what you specify in the name attribute for your radio buttons. 放在方括号中的是您在单选按钮的name属性中指定的内容。

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: 在register.php上:

<?php

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

?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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