我创建了一个测试表单,试图将来自gender表(包含:(1)male(2)female)的单选按钮值发送到另一个名为: ajebaje
. 我现在有点问题。下面的代码只是一个测试,我想单选按钮提交值,但它不是。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> ajebaje </title>
</head>
<body>
<form name="form1" action= "<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<table width="20%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td><h4> Student's Gender </h4></td>
<td>
<?php
$con=mysqli_connect("localhost", "root", "ew6wLoLOro", "result");
$sql=mysqli_query($con, "select gender_sl_no, gender_name from gender")
while($row=mysqli_fetch_array($sql))
{
echo '<table>
<input type="radio" name="sexbd" checked="checked"/>'.$row['gender_name'].'
</table>';
}
?>
</td>
</tr>
<tr>
<td> </td>
<td><input type ="submit" name="submit"/> </td>
</tr>
</table>
</form>
<?php
$con=mysqli_connect("localhost", "root", "ew6wLoLOro", "result");
$sexbd = $_POST['sexbd'];
if(isset($_POST['submit']))
{
echo $que="Insert into ajebaje VALUES(default,'$sexbd' )";
echo " ";
echo "Your Data Inserted";
$result = mysqli_query($con,$que);
}
?>
</body>
</html>
1条答案
按热度按时间zvokhttg1#
默认情况下,它应该发送
sexbd: on
在表格中。为了从表单发送值,需要在输入标记中定义value属性。像这样:
呈现的形式如下所示:
现在,提交的值将是
sexbd: Male
或者sexbd: Female