![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
php写页面,页面中有表单,但是运行页面时表单未填写也没有按提交按钮,后面的php代码就开始运行,怎么办
比如:<html><head><title>BorrowPage</title><style>.div3{font-size:40px;font-weight:bold;...
比如:
<html>
<head>
<title>BorrowPage</title>
<style>
.div3{
font-size:40px;
font-weight:bold;
}
</style>
</head>
<body>
<form method=get
name=form_borrow
action="#">
<br/><br/>
<h1><font font-size:80em color="#000">BORROW</font></h1><br/><br/><hr size=4px color="#f0ffff"/>
<br/><br/><br/><br/>
<h1><font color="#ddd">请输入要借的书的ISBN号:</font></h1>
<input type="text" name='book_isbn' style="width:400px;height:40px;background-color: #eee;border-style:solid;"/>
<input type="submit" value="查询" name='ok' style="width:120px;height:40px;background-color: #eee;border-style:groove;"/>
</form>
<?php
$conn=mysql_connect("localhost","root","")or die('连接失败');
mysql_select_db("library",$conn) or die('连接数据库失败');
if(!isset($_REQUEST['submit'])){
echo '非法访问';
}
$bookID=$_REQUEST['book_isbn'];
$query="select book_isbn from books where book_isbn==$bookID";
$query_result=mysql_query($query);
$result=mysql_fetch_array($query_result,$conn);
if(!$result)
{
echo "<script>alert('此书不存在')</script>";
}
$query2="select book_remian from books where book_isbn==$bookID";
$query_result2=mysql_query($query2)or die(mysql_error());
$result2=mysql_fetch_array($query_result2);
if($result==0)
{
echo "<script>alert('此书现库存为0')</script>";
}
else
{
echo "<script>alert('借书成功')</script>";
$query3="update books set book_remain as book_remain-1 where book_isbn==$bookID";
mysql_query($query3);
}
mysql_close($conn);
?>
</body>
</html>
运行时: 展开
<html>
<head>
<title>BorrowPage</title>
<style>
.div3{
font-size:40px;
font-weight:bold;
}
</style>
</head>
<body>
<form method=get
name=form_borrow
action="#">
<br/><br/>
<h1><font font-size:80em color="#000">BORROW</font></h1><br/><br/><hr size=4px color="#f0ffff"/>
<br/><br/><br/><br/>
<h1><font color="#ddd">请输入要借的书的ISBN号:</font></h1>
<input type="text" name='book_isbn' style="width:400px;height:40px;background-color: #eee;border-style:solid;"/>
<input type="submit" value="查询" name='ok' style="width:120px;height:40px;background-color: #eee;border-style:groove;"/>
</form>
<?php
$conn=mysql_connect("localhost","root","")or die('连接失败');
mysql_select_db("library",$conn) or die('连接数据库失败');
if(!isset($_REQUEST['submit'])){
echo '非法访问';
}
$bookID=$_REQUEST['book_isbn'];
$query="select book_isbn from books where book_isbn==$bookID";
$query_result=mysql_query($query);
$result=mysql_fetch_array($query_result,$conn);
if(!$result)
{
echo "<script>alert('此书不存在')</script>";
}
$query2="select book_remian from books where book_isbn==$bookID";
$query_result2=mysql_query($query2)or die(mysql_error());
$result2=mysql_fetch_array($query_result2);
if($result==0)
{
echo "<script>alert('此书现库存为0')</script>";
}
else
{
echo "<script>alert('借书成功')</script>";
$query3="update books set book_remain as book_remain-1 where book_isbn==$bookID";
mysql_query($query3);
}
mysql_close($conn);
?>
</body>
</html>
运行时: 展开
推荐于2016-03-04 · 知道合伙人软件行家
关注
![](https://wyw-base.cdn.bcebos.com/pc-content/follow.gif)
展开全部
<html>
<head>
<title>BorrowPage</title>
<style>
.div3{
font-size:40px;
font-weight:bold;
}
</style>
</head>
<body>
<form method=get
name=form_borrow
action="#">
<br/><br/>
<h1><font
font-size:80em
color="#000">BORROW</font></h1><br/><br/><hr
size=4px color="#f0ffff"/>
<br/><br/><br/><br/>
<h1><font color="#ddd">请输入要借的书的ISBN号:</font></h1>
<input type="text" name='book_isbn' style="width:400px;height:40px;background-color: #eee;border-style:solid;"/>
<input type="submit" value="查询" name='ok' style="width:120px;height:40px;background-color: #eee;border-style:groove;"/>
</form>
<?php
//判断下,没有提交post不执行后面的代码
if(!isset($_GET['book_isbn'])){
die;
}
$conn=mysql_connect("localhost","root","")or die('连接失败');
mysql_select_db("library",$conn) or die('连接数据库失败');
if(!isset($_REQUEST['submit'])){
echo '非法访问';
}
$bookID=$_REQUEST['book_isbn'];
$query="select book_isbn from books where book_isbn==$bookID";
$query_result=mysql_query($query);
$result=mysql_fetch_array($query_result,$conn);
if(!$result)
{
echo "<script>alert('此书不存在')</script>";
}
$query2="select book_remian from books where book_isbn==$bookID";
$query_result2=mysql_query($query2)or die(mysql_error());
$result2=mysql_fetch_array($query_result2);
if($result==0)
{
echo "<script>alert('此书现库存为0')</script>";
}
else
{
echo "<script>alert('借书成功')</script>";
$query3="update books set book_remain as book_remain-1 where book_isbn==$bookID";
mysql_query($query3);
}
mysql_close($conn);
?>
</body>
</html>
运行时:
您的回答被采纳后将获得系统奖励20(财富值+经验值)+15分钟内解答奖励20(财富值+经验值)[离结束还有03分03秒]
我要回答|搜索相关资料
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询