gpt4 book ai didi

php - 将单选按钮值插入 mysql

转载 作者:行者123 更新时间:2023-11-29 06:35:13 25 4
gpt4 key购买 nike

我已经创建了一个测试表单来尝试将我的单选按钮值发送到 mysql。我现在遇到了问题。下面的代码只是一个测试,我希望单选按钮提交值,但事实并非如此。

    <table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form1" method="post" action="insert_ac.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td colspan="3"><strong>TEST </strong></td>
</tr>
<tr>
<td width="71">Name</td>
<td width="6">:</td>
<td width="301"><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td>Case</td>
<td>:</td>
<td><input name="case" type="radio" id="case1"> <input name="case" type="radio" id="case2"> <input name="case" type="radio" id="case3"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="email" type="text" id="email"></td>
</tr>
<tr>
<td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>

这里是数据库的连接部分

<?php

$host="localhost"; // Host name
$username="root"; // Mysql username
$password="123"; // Mysql password
$db_name="store"; // Database name
$tbl_name="test_mysql"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Get values from form
$name=$_POST['name'];
$case=$_POST['case'];
$email=$_POST['email'];

// Insert data into mysql
$sql="INSERT INTO $tbl_name(name, case, email)VALUES('$name', '$case', '$email')";
$result=mysql_query($sql);

// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='insert.php'>Back to main page</a>";
}

else {
echo "ERROR";
}
?>

<?php
// close connection
mysql_close();
?>

最佳答案

这是通过向单选按钮输入添加值来完成的。例如:

<form method="post">
<input type="radio" name="sex" value="male">Male<br>
<input type="radio" name="sex" value="female">Female
<input type="submit">
</form>

关于php - 将单选按钮值插入 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25295516/

25 4 0
文章推荐: mysql - 在 Jooq 中集成 Hikari Pool
文章推荐: PHP