采用windows+apache+php+mysql进行本地调试html文件和php均放在www目录下,,事先已经在数据库中建好表,
在页面上填入数据,提交,为什么数据没有插入数据库,谢先!!
html代码
<html>
<body><form action="C:\wamp\www\test.php" method="post">
Firstname: <input type="text" name="firstname" />
Lastname: <input type="text" name="lastname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form></body>
</html>php代码<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}mysql_select_db("my_db", $con);$sql="INSERT INTO person (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";mysql_close($con)
?>
在页面上填入数据,提交,为什么数据没有插入数据库,谢先!!
html代码
<html>
<body><form action="C:\wamp\www\test.php" method="post">
Firstname: <input type="text" name="firstname" />
Lastname: <input type="text" name="lastname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form></body>
</html>php代码<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}mysql_select_db("my_db", $con);$sql="INSERT INTO person (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";mysql_close($con)
?>
不能写地址?程序换个地方就没办法用了mysql_select_db("my_db", $con); 这句改成:
mysql_select_db("my_db", $con) or die(mysql_error()); 有没有出错提示?最后这句:echo "1 record added"; 页面上有没有打印出来?
改为:
action="test.php"
请看安装教程。