对不起,如果这已经存在,但我无法在任何地方找到它。插入使用PHP显示为下载而不是执行
我试图从一个表格中插入信息到名为“instest”的数据库中名为“test”的表中。 “instest”表中的列是“firstName”,“lastName”和“age”。
问题是,每次点击提交按钮时,它会显示为下载(IE)或代码显示(Opera),而不是实际执行的代码。
下面是代码:
/* TestInsert.php */
<!DOCTYPE HTML>
<html>
<body>
<form action="Insert.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>
/* Insert.php */
<?php
$con = mysql_connect("localhost","[email protected]"); //No password
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$sql="INSERT INTO instest (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)
?>
还有一个开始'<?'? – fyr