我正在为一个学校项目开发一个非常简单的 CMS 系统,但遇到了一些麻烦。
现在,我的网页设置如下:
- 我创建的每个用户都可以访问的网页 - 在顶部和底部,我分别有一个 include_once(header.php) 和 include_once(footer.php)。这些包含应该被加载的任何页面的顶部和底部。
在我的 header.php 中,我有这个以及其他杂项 HTML:
<?php
require_once('php/constants.php');
require_once("php/functions.php");
?>
对于 constants.php - 包含我能想到的每一个已定义的常量,因为我宁愿在这里更改一个常量,也不愿在我的代码中搜索以找到我可以在其他地方拥有的许多实例。
For Functions.php - 包含我为在此 CMS 上使用而创建的每个函数。包含从我使用 PHPMailer 的电子邮件功能到使用 MeekroDB 进行数据库交互的注册和登录的所有内容。
问题就在这里。
在我用于帐户注册的页面上,有一些类似的内容
//get the username, password, first/last name, and send it to register function.
$firstName = $_POST['first_name'];
$lastName = $_POST['last_name'];
$password = $_POST['password'];
$email_address = $_POST['email_address'];
//register the user. where register() is in functions.php
if(register($email_address, $password, $firstName, $lastName))
{
echo "REGISTRATION SUCCESSFUL";
}
else
{
echo "REGISTRATION UNSUCCESSFUL";
}
在我的 functions.php 文件中,我使用 MeekroDB 提到的我使用的 DB::QUERY 分配声明我的数据库信息。
//MeekroDB - Used for database CRUDding
require_once("php/meekrodb.php");
DB::$user = 'root'; //yes i'll change this later
DB::$password = ''; //this too
DB::$dbName ="testDB";
在实际的注册功能中,我有这个:
function register($email, $password, $firstName, $lastName)
{
//check to see if the user already exists
//poll the DB to see if the email is already in there.
$results = DB::QUERY("SELECT email FROM users WHERE email = %s", $email);
//if there is a row in the DB with this email...
if(DB::count() >= 1)
{
return false;
}
else
{
//lets prepare the user for insertion into the database.
$username = $firstName . '_' . $lastName;
//generate a salt for database insertion and password hashing
$salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));
$password = hash('sha512', $password . $salt);
//create the insert statement array for insertion.
$insertionArray =
array(
'username' => $username,
'password' => $password,
'email' => $email,
'salt' => $salt,
'isAdmin' => 0
);
//insert the new user into the database.
DB::INSERT('users', $insertionArray);
//Send a registration email to the new user.
//Send an email to the user stating they've registered.
$mailer = createMailer();
//set the contents of the email
$mailer->MsgHTML(generateEmail_Registration($username));
//set the destination address
$mailer->AddAddress($email, $firstName . ' ' . $lastName);
if($mailer->Send())
{
return true;
}
else
{
return false;
}
}
}
对我来说,这应该有效。
然而:
每当我尝试运行 register() 函数时,我最终都会遇到大量涉及 MeekroDB 的错误,而且我不能 100% 确定如何修复它们(无论是 INCLUDE 问题,还是与 meekroDB 相关?)
这是我遇到的错误。
Warning: mysqli::set_charset(): invalid object or resource mysqli in D:\xampp\htdocs\finalproject\php\meekrodb.php on line 186
Warning: MeekroDB::get(): Property access is not allowed yet in D:\xampp\htdocs\finalproject\php\meekrodb.php on line 188
Warning: mysqli::real_escape_string(): invalid object or resource mysqli in D:\xampp\htdocs\finalproject\php\meekrodb.php on line 496
Warning: mysqli::query(): invalid object or resource mysqli in D:\xampp\htdocs\finalproject\php\meekrodb.php on line 628
Warning: MeekroDB::queryHelper(): Property access is not allowed yet in D:\xampp\htdocs\finalproject\php\meekrodb.php on line 662
Warning: MeekroDB::queryHelper(): Property access is not allowed yet in D:\xampp\htdocs\finalproject\php\meekrodb.php on line 663
Warning: mysqli::real_escape_string(): invalid object or resource mysqli in D:\xampp\htdocs\finalproject\php\meekrodb.php on line 496
Warning: mysqli::real_escape_string(): invalid object or resource mysqli in D:\xampp\htdocs\finalproject\php\meekrodb.php on line 496
Warning: mysqli::real_escape_string(): invalid object or resource mysqli in D:\xampp\htdocs\finalproject\php\meekrodb.php on line 496
Warning: mysqli::real_escape_string(): invalid object or resource mysqli in D:\xampp\htdocs\finalproject\php\meekrodb.php on line 496
Warning: mysqli::query(): invalid object or resource mysqli in D:\xampp\htdocs\finalproject\php\meekrodb.php on line 628
Warning: MeekroDB::queryHelper(): Property access is not allowed yet in D:\xampp\htdocs\finalproject\php\meekrodb.php on line 662
Warning: MeekroDB::queryHelper(): Property access is not allowed yet in D:\xampp\htdocs\finalproject\php\meekrodb.php on line 663
REGISTRATION UNSUCCESSFUL //of course.
我认为这与我包含各种 PHP 文件的方式有关,而这反过来又以某种方式破坏了我的 MeekroDB 连接。
如果你们需要更多信息,请告诉我,但我想我已经把所有东西都摆在了桌面上。
我不经常在这里发帖,所以如果我在某个地方错过了某种礼仪,我提前道歉。
谢谢!:)