<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<?php
if(isset($_POST["tj"])){
$bid=$_POST['bid'];
$bname=$_POST['bname'];
$sort=$_POST['sort'];
$author=$_POST['author'];
$press=$_POST['press'];
$price=$_POST['price'];
$summary=$_POST['summary'];
$time=$_POST['time'];
$conn=mysqli_connect('localhost','root','1234')or die('数据库服务器连接失败');
mysqli_set_charset($conn,'utf8');//设置字符集
mysqli_select_db($conn,'books') or die('数据库未找到');
$sql="insert into list (bid,bname,sort,author,press,price,summary,time) values ('$bid','$bname','$sort','$author','$press','$price','$summary','$time')";
$result=mysqli_query($conn,$sql);
if($result){
echo '添加数据成功';
}else{
echo '添加数据失败'.mysqli_error($conn);//mysqli_error()获取错误信息
}
mysql_free_result($result); # 释放结果集
mysqli_close($conn); // 关闭资源
}
?>
<form action="" method="post">
<p>图书编号:<input type="number" min=101 max=199 name="bid"></p>
<p>书名:<input type="text" name="bname"></p>
<p>所属种类:<select name="sort">
<option value="历史">历史</option>
<option value="童书">童书</option>
<option value="小说">小说</option>
</select>
</p>
<p>上传封面:<input type="file" name="pic"></p>
<p>作者:<input type="text" name="author"></p>
<p>出版社:<input type="text" name="press"></p>
<p>定价:<input type="text" name="price"></p>
<p>图书简介:<textarea rows="5" cols="30" name="summary"></textarea> </p>
<p>入库时间:<input type="date" name="time"> </p>
<p><input type="submit" name="tj" value="提交"></p>
</form>
</body>
</html>