为什么刷新页面数据库就添加一条记录?
php代码如下:<html><formaction="a.php"method="post">name:<inputtype="text"name="name"/>val...
php代码如下:
<html>
<form action="a.php" method="post">
name: <input type="text" name="name" />
val: <input type="text" name="val" />
unit: <input type="text" name="unit" />
<input type="submit" />
</form>
</html>
<?php
$a="$_POST[name]";
$b="$_POST[val]";
$c="$_POST[unit]";
$con = mysql_connect("localhost","root","king0105");
if(!$con){
die('Could not connect:' . mysql_error());
}
mysql_select_db("work",$con);
$sql="INSERT INTO usr(name,val,unit) VALUES ('$a','$b','$c')";
if($a=$b=$c=""){
echo "你没有输入";
}else{
if(!mysql_query($sql,$con)){
die('Error:'. mysql_error());
}
echo"一条记录以添加!";
}
mysql_close($con);
?> 展开
<html>
<form action="a.php" method="post">
name: <input type="text" name="name" />
val: <input type="text" name="val" />
unit: <input type="text" name="unit" />
<input type="submit" />
</form>
</html>
<?php
$a="$_POST[name]";
$b="$_POST[val]";
$c="$_POST[unit]";
$con = mysql_connect("localhost","root","king0105");
if(!$con){
die('Could not connect:' . mysql_error());
}
mysql_select_db("work",$con);
$sql="INSERT INTO usr(name,val,unit) VALUES ('$a','$b','$c')";
if($a=$b=$c=""){
echo "你没有输入";
}else{
if(!mysql_query($sql,$con)){
die('Error:'. mysql_error());
}
echo"一条记录以添加!";
}
mysql_close($con);
?> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询