给你改了一下,你试一试
<?php
if ($submit)
{$db=mysql_connect("localhost","root");
mysql_select_db("testdb1",$db);
$sql="INSERT INTO employees (first,last,address,position) VALUES('$first','$last','$address','$position')";
$result=mysql_query($sql);
echo "Thank you! information entered./n";}
else
{
echo"
<html>
<head>
<title> t1</title>
</head>
<body>
<form method='post' action='' >
名: <input type='Text' name='first'><>
姓:<input type='Text' name='last'><>
住址:<input type='Text' name='address'><>
职位:<input type='Text' name='position'><>
<input type='submit' name='submit' value='输入信息'>
</form>
</body>
</html>";}
?>
<?php
if ($submit)
{$db=mysql_connect("localhost","root");
mysql_select_db("testdb1",$db);
$sql="INSERT INTO employees (first,last,address,position) VALUES('$first','$last','$address','$position')";
$result=mysql_query($sql);
echo "Thank you! information entered./n";}
else
{
echo"
<html>
<head>
<title> t1</title>
</head>
<body>
<form method='post' action='' >
名: <input type='Text' name='first'><>
姓:<input type='Text' name='last'><>
住址:<input type='Text' name='address'><>
职位:<input type='Text' name='position'><>
<input type='submit' name='submit' value='输入信息'>
</form>
</body>
</html>";}
?>
那么用echo $PHP_SELF; 有没有输出结果?
我估计也没有。
2、把$submit 改为 $_POST["submit"]
把$PATH_SELF 改为 $_SERVER["PHP_SELF"]
把其他表单变量,由$first的形式改为$_POST["first"]的形式
PATH_SELF 是程序所在的路径,有些服务器不提供。用PHP_SELF一样
$submit的值是“输入信息”,你在表单里给的是否需要使用$_XXX一类的环境数组,最简单的判断方法就是
看看$PHP_SELF有没有值,有就可以不要用。