gpt4 book ai didi

php - fatal error : Call to a member function prepare() on a non-object in

转载 作者:太空宇宙 更新时间:2023-11-03 11:57:20 25 4
gpt4 key购买 nike

<分区>

另一个“ fatal error :调用成员函数 prepare() on a non-object in”的问题,但给出的答案无助于解决我的问题!

我正在尝试将通过邮寄从表单收到的信息写入并使用 php 将其写入 mysql 数据库。

错误:

Fatal error: Call to a member function prepare() on a non-object in /home/.../myform.php on line 17

我的 php 代码:

<?PHP

session_start();


require("DBconnect.php");

/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
// data sent from contactForm


// prepare and bind
$stmt = $conn->prepare("INSERT INTO Final (user_name, first_name, last_name) VALUES (?, ?, ?)");
$stmt->bind_param("sss", $user_name, $first_name, $last_name);

// set parameters from POST request and execute
$user_name = $_POST['user_name'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$stmt->execute();


echo "New records created successfully";

$stmt->close();
$mysqli->close();

?>

我的 DBconnect.php 包含以下内容:

<?php
$mysqli = new mysqli('localhost', 'user', 'pasword', 'dbname');
?>

25 4 0
文章推荐: python - 对可以从 Flash/HTML5 视频捕获静止图像的 Python 库的建议?
文章推荐: c# - 在 SignalR ASP.NET Core 3.0 中尝试使用 IAsyncEnumerable Catch
文章推荐: python - 使用子进程模块从 python 启动 jython 程序?
文章推荐: c# - c#中的数据表到XML,其中一些项目是列表