在下新手,以下为我的代码,请大家帮忙差错,我检查不出来
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>图书入库</title>
<style type="text/css">
<!--
.STYLE1 {
font-family: "华文新魏";
font-size: 36px;
font-weight: bold;
}
.STYLE2 {
font-family: "华文新魏";
font-weight: bold;
}
.STYLE3 {
font-family: "华文新魏";
font-size: 24px;
font-weight: bold;
}
.STYLE4 {font-size: 18px}
.STYLE5 {font-size: 18px; font-weight: bold; }
.STYLE8 {font-family: "华文新魏"}
.STYLE9 {font-size: 24px}
.STYLE10 {font-size: 16px}
body {
background-image: url(1.jpg);
}
-->
</style>
</head><body>
<div align="center" class="STYLE1">图书入库</div>
<form name="单本入库" method="post" action="" > <p align="center" class="STYLE3">单本入库</p>
<p align="center" class="STYLE5"><span class="STYLE2">书号:</span>
<input type="text" name="book_num" />
<span class="STYLE2">类 别: </span>
<input type="text" name="category" />
<span class="STYLE2">书名:</span>
<input type="text" name="title" />
</p>
<p align="center" class="STYLE5"><span class="STYLE2">出版社:</span>
<input type="text" name="publisher" />
<span class="STYLE2">年份: </span>
<input type="text" name="date_year" />
<span class="STYLE2">作者:</span>
<input type="text" name="author" />
</p>
<p align="center" class="STYLE4"><span class="STYLE2">价格: </span>
<strong>
<input type="text" name="price" />
<span class="STYLE8">总藏书量:</span></strong>
<strong>
<input type="text" name="total_num" />
<span class="STYLE8">库存:</span></strong>
<input type="text" name="stock_num" />
</p>
<p align="center"><input type="submit" name="Submit" value="图书入库" />
<input type="reset" name="Submit2" value="重新输入" /> </p>
</form>
<form name="批量入库" method="post" action="">
<p align="center" class="STYLE8 STYLE9">批量入库</p>
<p align="center" class="STYLE4"><span class="STYLE2">批量图书: </span>
<strong>
<input type="file" name="loadedfile" />
</strong></p>
<p align="center"><input type="submit" name="Submit" value="图书入库" /></p>
</form>
<?
if($_SERVER["REQUEST_METHOD"]=="POST"){
$boo_num1=$_POST['book_num'];
$category1=$_POST['category'];
$title1=$_POST['title'];
$publisher1=$_POST['publisher'];
$date_year1=$_POST['date_year'];
$author1=$_POST['author'];
$price1=$_POST['price'];
$total_num1=$_POST['total_num'];
$stock_num1=$_POST['stock_num']; mysql_connect("localhost","root","ps") or
die("Could not connect:".mysql.error());
mysql_select_db("library"); //判断书号是否已经存在
$strSql = "select * from book where book_num='$book_num1'";
$result=mysql_query($strSql);
$num=mysql_numrows($result);
if($num<>0) //如果找到,出错
{ mysql_close(); //关闭数据库连接
echo "<br><br><br><center><font color=yellow>该图书已存在!</font><br><br><br><br></center>";
}
else //将书添加到数据库
{ $result = mysql_query("insert into book values('book_num1','$category1','$title1','$publisher1','$date_year1','$author1','$price]','$total_num1','$stock_num1')");
mysql_close(); //关闭数据库连接
echo "<br><br><br><center><font color=yellow>图书单本入库成功!</font><br><br><br><br></center>";
}
}
?>
<?
if($_SERVER["REQUEST_METHOD"]=="POST"){
mysql_connect("localhost","root","ps") or
die("Could not connect:".mysql.error());
mysql_select_db("library"); mysql_query("set names utf8");
$filename = $_FILES['up_file']['tmp_name'];
$file=fopen("$filename","r");
fgets("$file"); if(isset($loadedfile))
{ while(!feof($file))
{ $rs = explode("\t",fgets($file));
$book_num1=$rs[1];
$category1=$rs[2];
$title1= $rs[3];
$publisher1 = $rs[4];
$date_year1= $rs[5];
$author1 = $rs[6];
$price1 = $rs[7];
$total_num1 = $rs[8];
$stock_num1 = $rs[9];
$sql="insert into book(book_num,category,title,publisher,date_year,author,price,total_num,stock_num) values('$book_nun[0]','$category1[0]','$title1[0]','$publisher1[0]','$date_year1[0]','$author1[0]','$price1[0]','$total_num1[0]','$stock_num1[0]')";
$result=mysql_query($sql);
}
echo "<br><br><br><center><font color=yellow>图书批量入库成功!<font><br><br><br><br></center>";
mysql_close(); //关闭数据库连接
fclose($file);
exit;
}
else
{ echo "<br><br><br><center><font color=red>图书批量入库失败!<font><br><br><br><br></center>";
mysql_close(); //关闭数据库连接
fclose("$file");
exit;
}
}
?><br /><br />
<div align="center">
<HR>
<p><font face="华文新魏" color="blue"><strong><span class="STYLE8"><a href="index.html">首页</a>/<a href="login.php">管理员登录</a>/<a href="searchbook.html">图书查询</a></span></strong></font><br>
</p>
<HR>
<P ALIGN=\"CENTER\"> <SMALL> <I> Copyright by <? echo " "; ?> , 2010</I> </SMALL> </P>
</div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>图书入库</title>
<style type="text/css">
<!--
.STYLE1 {
font-family: "华文新魏";
font-size: 36px;
font-weight: bold;
}
.STYLE2 {
font-family: "华文新魏";
font-weight: bold;
}
.STYLE3 {
font-family: "华文新魏";
font-size: 24px;
font-weight: bold;
}
.STYLE4 {font-size: 18px}
.STYLE5 {font-size: 18px; font-weight: bold; }
.STYLE8 {font-family: "华文新魏"}
.STYLE9 {font-size: 24px}
.STYLE10 {font-size: 16px}
body {
background-image: url(1.jpg);
}
-->
</style>
</head><body>
<div align="center" class="STYLE1">图书入库</div>
<form name="单本入库" method="post" action="" > <p align="center" class="STYLE3">单本入库</p>
<p align="center" class="STYLE5"><span class="STYLE2">书号:</span>
<input type="text" name="book_num" />
<span class="STYLE2">类 别: </span>
<input type="text" name="category" />
<span class="STYLE2">书名:</span>
<input type="text" name="title" />
</p>
<p align="center" class="STYLE5"><span class="STYLE2">出版社:</span>
<input type="text" name="publisher" />
<span class="STYLE2">年份: </span>
<input type="text" name="date_year" />
<span class="STYLE2">作者:</span>
<input type="text" name="author" />
</p>
<p align="center" class="STYLE4"><span class="STYLE2">价格: </span>
<strong>
<input type="text" name="price" />
<span class="STYLE8">总藏书量:</span></strong>
<strong>
<input type="text" name="total_num" />
<span class="STYLE8">库存:</span></strong>
<input type="text" name="stock_num" />
</p>
<p align="center"><input type="submit" name="Submit" value="图书入库" />
<input type="reset" name="Submit2" value="重新输入" /> </p>
</form>
<form name="批量入库" method="post" action="">
<p align="center" class="STYLE8 STYLE9">批量入库</p>
<p align="center" class="STYLE4"><span class="STYLE2">批量图书: </span>
<strong>
<input type="file" name="loadedfile" />
</strong></p>
<p align="center"><input type="submit" name="Submit" value="图书入库" /></p>
</form>
<?
if($_SERVER["REQUEST_METHOD"]=="POST"){
$boo_num1=$_POST['book_num'];
$category1=$_POST['category'];
$title1=$_POST['title'];
$publisher1=$_POST['publisher'];
$date_year1=$_POST['date_year'];
$author1=$_POST['author'];
$price1=$_POST['price'];
$total_num1=$_POST['total_num'];
$stock_num1=$_POST['stock_num']; mysql_connect("localhost","root","ps") or
die("Could not connect:".mysql.error());
mysql_select_db("library"); //判断书号是否已经存在
$strSql = "select * from book where book_num='$book_num1'";
$result=mysql_query($strSql);
$num=mysql_numrows($result);
if($num<>0) //如果找到,出错
{ mysql_close(); //关闭数据库连接
echo "<br><br><br><center><font color=yellow>该图书已存在!</font><br><br><br><br></center>";
}
else //将书添加到数据库
{ $result = mysql_query("insert into book values('book_num1','$category1','$title1','$publisher1','$date_year1','$author1','$price]','$total_num1','$stock_num1')");
mysql_close(); //关闭数据库连接
echo "<br><br><br><center><font color=yellow>图书单本入库成功!</font><br><br><br><br></center>";
}
}
?>
<?
if($_SERVER["REQUEST_METHOD"]=="POST"){
mysql_connect("localhost","root","ps") or
die("Could not connect:".mysql.error());
mysql_select_db("library"); mysql_query("set names utf8");
$filename = $_FILES['up_file']['tmp_name'];
$file=fopen("$filename","r");
fgets("$file"); if(isset($loadedfile))
{ while(!feof($file))
{ $rs = explode("\t",fgets($file));
$book_num1=$rs[1];
$category1=$rs[2];
$title1= $rs[3];
$publisher1 = $rs[4];
$date_year1= $rs[5];
$author1 = $rs[6];
$price1 = $rs[7];
$total_num1 = $rs[8];
$stock_num1 = $rs[9];
$sql="insert into book(book_num,category,title,publisher,date_year,author,price,total_num,stock_num) values('$book_nun[0]','$category1[0]','$title1[0]','$publisher1[0]','$date_year1[0]','$author1[0]','$price1[0]','$total_num1[0]','$stock_num1[0]')";
$result=mysql_query($sql);
}
echo "<br><br><br><center><font color=yellow>图书批量入库成功!<font><br><br><br><br></center>";
mysql_close(); //关闭数据库连接
fclose($file);
exit;
}
else
{ echo "<br><br><br><center><font color=red>图书批量入库失败!<font><br><br><br><br></center>";
mysql_close(); //关闭数据库连接
fclose("$file");
exit;
}
}
?><br /><br />
<div align="center">
<HR>
<p><font face="华文新魏" color="blue"><strong><span class="STYLE8"><a href="index.html">首页</a>/<a href="login.php">管理员登录</a>/<a href="searchbook.html">图书查询</a></span></strong></font><br>
</p>
<HR>
<P ALIGN=\"CENTER\"> <SMALL> <I> Copyright by <? echo " "; ?> , 2010</I> </SMALL> </P>
</div>
</body>
</html>
图书批量入库失败!Warning: fclose(): supplied argument is not a valid stream resource in F:\icebiangzi\APMServ5.2.0\www\htdocs\bookinsystem.php on line 139
enctype="multipart/form-data"