好久没写原生SQL了,来个添加
<?php
if($_POST) {
header("Content-type: text/html; charset=utf-8");
!empty($_POST['Fruit']) && $fruit=$_POST['Fruit'];
!empty($_POST['other']) && $fruit=$_POST['other'];
//数据量链接
$conn=mysqli_connect("127.0.0.1",'root',"root",'test');
$sql="insert into `test` (`option`) VALUES ('".$fruit."')";
$result=mysqli_query($conn,$sql);
echo '添加成功!';
} else {
?>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
function showinput()
{
$("#other").show();
}
</script>
<form action="index.php" method="post">
您最喜欢水果?<br /><br />
<br /><input name="Fruit" type="radio" value="苹果" />苹果
<br /><input name="Fruit" type="radio" value="桃子" />桃子
<br /><input name="Fruit" type="radio" value="香蕉" />香蕉
<br /><input name="Fruit" type="radio" value="梨" />梨
<br /><input onclick="showinput();" name="Fruit" type="radio" value="0" />其它
<div id="other" style="display:none"><input name="other" type="text" value="" /></div><br>
<input type="submit" value="提交">
</form>
<?php
}
?>