我想把前台选中的checkbox保存到数据库应该怎么搞,希望大神可以帮我改一下。多谢大神们。
这是前台代码
<html>
<head>
<meta http-equiv="content-type";content-type="text/html;charset=utf-8"/>
<title>注册页面</title>
</head>
<h1>注册页面</h1>
<form action="addprocess.php" method="post">
名字<input type="text" name="name" id="name" /><br/>
性别:<input type="radio" name="sex" id="sex" value="男" >男<input type="radio" name="sex" value="女" >女<br/>
专业<select name="education" >
<option value="大专">大专</option>
<option value="本科" >本科</option>
<option value="研究生" >研究生</option>
</select><br/>
级别:<input type="number" name="grade"><br/>
email:<input type="email" name="email" /><br/>
工资:<input type="number" name="salary"><br/>
兴趣:<input type="checkbox" name="hobby" value="羽毛球">羽毛球
<input type="checkbox" name="hobby" value="乒乓球">乒乓球
<input type="checkbox" name="hobby" value="网球">网球
<input type="submit" value="提交" />
</form>
</html>
这是后台代码
<?php
$name=$_POST['name'];$sex=$_POST['sex'];
$education=$_POST['education'];
$grade=$_POST['grade'];$email=$_POST['email'];$salary=$_POST['salary'];
$conn=mysql_connect("127.0.0.1","root","123456");
if(!$conn){
die(mysql_errno());
}
mysql_select_db("empmanage",$conn) or die(mysql_errno());
mysql_query("set names utf8",$conn) or die(mysql_errno);
$sql="insert into emp(name,sex,education,grade,salary,email) values('$name','$sex','$education','$grade','$salary','$email')";
$res=mysql_query($sql,$conn);
if($res){
header("Location:ok.php");
exit();
}else{
header("Location:empList.php");
exit();
}
?>
phper12138
初学乍练2
慕田峪3555374