2017-06-18 07:53
浏览 77


I want to use radio buttons in my application.When i click Male , i want it to input male into the database, when i click Female, it sends female into the database.

Code looks like this

<title>Radio Test</title>
<h1>Radio Test</h1>
<form name="testform" id="testform" method="post" action="test.php" />
Name : <input type="text" name="fullname" id="fullname" /></br>
    Male <input type="radio" name="male" id="male" value="Male" />
    Female <input type="radio" name="female" id="female" value="FeMale" /></br></p>
        <input type="submit" name="submit" value="Submit" />

For the HTML Area, Now i want to make it output values, but it doesnt respond. My PHP looks like this but instead of sending one value, it sends both


$host = ""
$user = "root"
$pass = ""
$db = "people_info"

$con = mysqli_connect($host, $user, $pass, $db) or die('Cannot Connect :'.mysqli_error());
$fullname = mysqli_real_escape_string($con, $_POST['fullname']);
$male = mysqli_real_escape_string($con, $_POST['male']);
$female = mysqli_real_escape_string($con, $_POST['female']);

$sql = "insert into data (fullname,male,female) values ('".$fullname."', '".$male."', '".$female."')";
mysqli_query($con,$sql) or die ('Failed Query :'.mysqli_error($con));

I was thinking of using switch case, but that made it even worse. It didnt send any values as well..

图片转代码服务由CSDN问答提供 功能建议

我想在我的应用程序中使用单选按钮。当我单击Male时,我希望它输入male到数据库中 当我点击女性时,它会将女性发送到数据库中。

代码看起来像这样 <前> &lt; html&gt; &lt; head&gt ;&lt; / head&gt; &lt; title&gt; Radio Test&lt; / title&gt; &lt; body&gt; &lt; h1&gt; Radio Test&lt; / h1&gt; &lt; form name =“testform”id =“testform”method =“ post“action =”test.php“/&gt; 名称:&lt; input type =”text“name =”fullname“id =”fullname“/&gt;&lt; / br&gt; 男性&lt; input type =” radio“name =”male“id =”male“value =”男性“/&gt; 女性&lt; input type =”radio“name =”female“id =”female“value =”FeMale“/&gt;&lt; ; / br&gt;&lt; / p&gt; &lt; input type =“submit”name =“submit”value =“Submit”/&gt; &lt; / form&gt; &lt; / body&gt; &lt; / html&gt;

对于HTML区域,现在我想让它成为输出值,但它没有响应。 我的PHP看起来像这样但不发送一个值,而是发送

 $ host =“”
 $ user =  “root”
 $ pass =“”
 $ db =“people_info”
 $ con = mysqli_connect($ host,$ user,$ pass,$ db)或die('Can not Connect:'。mysqli_error(  )); 
 $ fullname = mysqli_real_escape_string($ con,$ _POST ['fullname']); 
 $ male = mysqli_real_escape_string($ con,$ _POST ['male']); 
 $ female = mysqli_real_escape_string($ con  ,$ _POST ['female']); 
 $ sql =“插入数据(全名,男性,女性)值('”。$ fullname。“','”。$ male。“','”  。$ female。“')”; 
mysqli_query($ con,$ sql)或die('Failed Query:'。mysqli_error($ con)); 
mysqli_close($ con); 

我在考虑使用switch case,但这让它变得更糟。 它也没有发送任何值..

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • dow46218 2017-06-18 07:59

    I think, you should have one column Gender in your table. I'm not sure why are you storing it in two different column.

    Change your code to following

    Male <input type="radio" name="gender" id="male" value="Male" />
    Female <input type="radio" name="gender" id="female" value="FeMale" /></br></p>


     $gender = mysqli_real_escape_string($con, $_POST['gender']);
    解决 无用
    打赏 举报

相关推荐 更多相似问题