我的单选按钮的值为“1”,“2”,“3”,我的数据库设置为接收值为INT。但是,在提交表单时,它们会在每个字段中作为零进入数据库。这是JS Fiddle
<p><input type="radio" name="buttons" value="1">A-Flat
//我已连接数据库
// variables
$frets = $_POST["fret"];
$fonts = $_POST["fonts"];
$buttons = $_POST["buttons"];
// if else to display the results
if(isset($_POST['submit'])) {
// mysql
$query = "INSERT INTO $tbl_name (frets, fonts, buttons) VALUES ('$frets','$fonts','$buttons') ";
mysql_query ($query);
mysql_close();
// stuff
echo '<h1>Thanks!!</h1>','<p>',"I lied about the prize. Here is a funny video to make up for it.",'</p>','<br />',
'<iframe width="560" height="315" src="http://www.youtube.com/embed/3-HCs4tRw8o" frameborder="0" allowfullscreen></iframe>';
}
else {
// page header
echo '<h1>', "You broke it!",'</h1> ';
// message
echo '<h3 style=text-align:center;>',"Silly Rabbit! Make sure you fill out all the fields!", "<br>",
"<a href=usertesting.php>Try again.</a>",'</h3>';
}
?>
答案 0 :(得分:1)
1.追踪$buttons
的价值,即echo $buttons;
,看看会发生什么。
2.将查询更改为:
$query = "INSERT INTO $tbl_name (frets, fonts, buttons) VALUES ('".$frets."','".$fonts."','".$buttons."') ";
mysql_query ($query);
3。另请检查数据库中buttons
的数据类型
您的查询很容易被SQL注入,请将其设为seccure。
mysql_ *函数被删除使用mysqli_ *函数或PDO