<?php
include('./conn/conn.php');
function toGBK($str){
return iconv('UTF-8', 'GBK', $str);
}
if(!empty($_POST)){
$name=$_POST['name'];
$sex=$_POST['sex'];
$sno=$_POST['sno'];
$dept=$_POST['dept'];
$age=$_POST['age'];
$sno=toGBK($sno);
$name=toGBK($name);
$sex=toGBK($sex);
$dept=toGBK($dept);
$sql = "insert into Student(Sno,Sname,Ssex,Sage,Sdept) values('$sno','$name','$sex',$age,'$dept')";
echo $sql;
$result = sqlsrv_query($conn, $sql) or die("数据插入失败!");
header("location:index.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>添加学生信息</title>
<style type="text/css">
html {
font-size: 15px;
}
fieldset {
width: 450px;
margin: 0 auto;
}
legend {
font-weight: bold;
font-size: 18px;
}
label {
float: left;
width: 70px;
margin-left: 10px;
}
.left {
margin-left: 80px;
}
.input {
width: 200px;
border: 1px solid #ccc;
padding: 7px 0px;
border-radius: 3px; /*css3属性IE不支持*/
padding-left: 5px;
}
span {
color: #666666;
}
p{
margin-left: 30px;
}
</style>
</head>
<body>
<fieldset>
<legend>添加个人信息</legend>
<form name="addForm" method="post" action="#">
<p>
<label for="sno" class="label">学号:</label>
<input id="sno" name="sno" type="text" class="input" />
<p/>
<p>
<label for="name" class="label">姓名:</label>
<input id="name" name="name" type="text" class="input" />
<p/>
<p>
<label for="sex" class="label">性别:</label>
<input name="sex" type="radio" value="男" >男
<input name="sex" type="radio"value="女">女
<p/>
<p>
<label for="age" class="label">年龄:</label>
<input id="age" name="age" type="text" class="input" />
<p/>
<p>
<label for="dept" class="label">学院:</label>
<input id="dept" name="dept" type="text" class="input" />
<p/>
<p>
<input type="reset" value=" 重 置 "/>
<input type="submit" name="submit" value=" 提 交 " class="left" />
</p>
</form>
</fieldset>
</body>
</html>