尝试将 php 连接到 mySQL 后,有没有办法解决错误 405?

问题描述 投票:0回答:1

在尝试将 php 与 mySQL 数据库连接后,我遇到了错误 405。下面是我的代码片段;

`<?php
$mysqli = new mysqli('localhost', 'root', 'password', 'dexnetworks');
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);

}

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$userName = $_POST['userName'];
$phoneNumber = $_POST['phoneNumber'];
$email = $_POST['email'];
$password = $_POST['password'];

$stmt = $conn->prepare("INSERT INTO register (userName, phoneNumber, email, password) VALUES (?, ?, ?,   ?)");
$stmt->bind_param("ssss", $userName, $phoneNumber, $email, $password);

if ($stmt->execute() === TRUE) {
    echo "Record added successfully";
} else {
    echo "Error: " . $conn->error;
}

$stmt->close();
}
$conn->close();
?>`

我编写了一个PHP代码,用于将数据库连接到我的网站,其中我的注册选项卡是register.html,之后我尝试注册一个新用户,希望注册成功,但我被重定向到错误405页面。

php mysql database mysqli xampp
1个回答
0
投票

尝试在配置中使用此代码,它工作正常。

 $server_name = "localhost";
 $username = "username";
 $password = "password";
 $db_name = "database_name";

 // Create connection
 $conn = new mysqli($server_name,
 $username, $password, $db_name);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: "
    . $conn->connect_error);
}

$sql_query = "INSERT INTO table VALUES
('John', 'Doe', '[email protected]')"

if ($conn->query($sql) === TRUE) {
    echo "record inserted successfully";
} else {
  echo "Error: " . $sql . "<br>" . $conn->error;
}
© www.soinside.com 2019 - 2024. All rights reserved.