【问题标题】:can someone help me when i send this form i get the php displayed instead of it executed the php code当我发送此表单时,有人可以帮助我吗?我显示 php 而不是执行 php 代码
【发布时间】:2013-10-22 23:55:35
【问题描述】:

当我尝试设置一个将信息发送到 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);
?>

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

【问题讨论】:

  • 如果您的浏览器显示insert.php文件的全部内容,那么它没有正确安装php。
  • forminsert.php 代码在同一个文件中吗?
  • 是的,表单文件和 insert.php 都在它们自己的文件夹中

标签: php html mysql database forms


【解决方案1】:

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

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

【讨论】:

  • 好的,我将如何配置我的浏览器(safari)来运行 php 代码
  • @Daniel 不是浏览器;存储代码的网络服务器。
  • 我不知道我正在运行什么版本的 php,但我的浏览器是最新的,我正在使用最新版本的 text wrangler
  • a 我正在使用 mysql,一切都应该是最新的我正在使用 localhost,我正在通过 myphpadmin 运行它
  • @daniel 听起来您在 Mac 上运行?你在你的 apache 配置中启用了 php 吗?尝试按照此页面上的步骤php.about.com/od/phpbasics/ss/installMac_2.htm
猜你喜欢
  • 1970-01-01
  • 2020-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-22
  • 2018-04-17
  • 2022-06-11
  • 1970-01-01
相关资源
最近更新 更多