【发布时间】: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