当我发送这个表单时,有人可以帮助我,我会显示php而不是执行php代码

时间:2013-10-22 23:55:36

标签: php html mysql database forms

当我尝试设置一个将信息发送到mysql的html表单时,总是显示php代码而不是在这里执行是我的代码可以有人请解释我在哪里错误花了一周拖着互联网寻找一个在我的工作中回答并仍然没有进一步了解

html表单页面:

<html>
<body>

<form action="insert.php" method="post">
students name: <input type="text" name="studentsname">
students form: <input type="text" name="studentsform">
teachers id: <input type="text" name="teachersid">
<input type="submit">
</form>

</body>
</html>

现在下一位是mysql数据库的代码

<?php
$con=mysqli_connect("localhost","root","","onduty");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql="INSERT INTO on duty request (studentsname, studentsform, teachersid)
VALUES
('$_POST[studentsname]','$_POST[studentsform]','$_POST[teachersid]')";

if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";

mysqli_close($con);
?>

我真的可以使用someones帮助向我解释为什么显示php代码而不是执行 谢谢 丹尼尔

1 个答案:

答案 0 :(得分:2)

如果您的脚本没有运行,并且您在浏览器中看到php代码,则听起来您的Web服务器配置不正确。

可能是很多东西;需要更多信息。您正在运行什么Web服务器,安装了什么版本的php,正确安装了php等等。