<html>
<head>
<title>database connection</title>
</head>
<body>
<?php
$mylink=mysql_connect("localhost","root","123456")or die("无法连接数据库");
//echo $mylink;
mysql_select_db("mydata",$mylink);
if(isset($_POST['sub']))
{
$str="insert into dept(deptno,dename,location)values('$_POST[deptno]','$_POST[dename]','$_POST[location]')";
//echo $str;
$result=mysql_query($sql,$mylink);
echo $result;
if(mysql_affected_rows($mylink)!=0)
echo "OK!";
else
echo "Error!";
}
mysql_close($mylink);
?>
<form action="index.php" method="post">
系号:<input type="text" name="deptno"/></br>
系名:<input type="text" name="dename"/></br>
所在地:<input type="text" name="location"/></br>
<input type="submit" name="sub" value="提交"/></br>
</form>
</body>
</html>
上面这段代码为什么按钮还没按钮就执行,如何检测按钮被按下??