【问题标题】:Php code is not executing instead displaying in web browser [duplicate]PHP代码没有执行,而是显示在网络浏览器中[重复]
【发布时间】:2021-07-31 00:11:08
【问题描述】:

我没有使用任何 Xampp 或 wampp,我已经手动安装并配置了以下所有软件:

apache
php
phpmyadmin
mysql

我什至通过在 apache 的“C:/Apache/htdocs”文件夹中创建一个“test.php”文件来测试 php 是否正常工作。

问题: 我正在创建注册表单,我已将 connect.php 附加到 index.html,它们存在于文件夹“C:/Apache/htdocs/Test”中,但 php 代码并未执行,而是.php 文件正在浏览器中显示。

<?php
    $firstName = $_POST['firstName'];
    $lastName = $_POST['lastName'];
    $gender = $_POST['gender'];
    $email = $_POST['email'];
    $password = $_POST['password'];
    $number = $_POST['number'];

    // Database connection
    $conn = new mysqli('localhost','root','abcdefg','test');
    if($conn->connect_error){
        echo "$conn->connect_error";
        die("Connection Failed : ". $conn->connect_error);
    } else {
        $stmt = $conn->prepare("insert into registration(firstName, lastName, gender, email, password, number) values(?, ?, ?, ?, ?, ?)");
        $stmt->bind_param("sssssi", $firstName, $lastName, $gender, $email, $password, $number);
        $execval = $stmt->execute();
        echo $execval;
        echo "Registration successfully...";
        $stmt->close();
        $conn->close();
    }
?>

.html 文件中的连接:

<div class="panel-body">
            <form action="connect.php" method="post">

【问题讨论】:

  • 您可以尝试将 index.html 更改为 index.php 吗?
  • 您测试了 PHP 是否在 htdocs 文件夹中工作,但似乎它在您的 htdocs/Test 文件夹中不起作用。这将是您的 apache 中的配置错误。
  • 你知道配置哪里出错了吗?youtu.be/cm5L2EXA_t4我配置的链接。
  • 我什至尝试将 .html 和 .php 文件都保存在 htdocs 本身中,但仍然面临同样的问题。
  • 将 index.html 更改为 index.php 有效,您节省了我的时间 :) @OmarFaruque

标签: php html mysql apache


【解决方案1】:

似乎 apache 的文档没有任何 php 集成或 php 服务未在该特定目录中运行。

【讨论】:

  • 整个 php 代码(我粘贴在问题中)在我运行 .html 后显示在网络浏览器中
  • 能分享一下你使用的php和apache的版本吗?
猜你喜欢
  • 2023-01-28
  • 2021-07-31
相关资源
最近更新 更多