我正在为一个学校项目开发一个非常简单的CMS系统,我遇到了一些麻烦。
现在,我的网页设置如下:
在我的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的问题?)< / p>
以下是我遇到的错误。
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连接。
如果你们需要更多信息,请告诉我,但我想我已经把所有东西都拿出来了。
我不经常在这里发帖,所以如果我错过某个地方的某种礼节,我会事先道歉。
谢谢! :)
答案 0 :(得分:1)
如果你跟随meekrodb.php文件,你的$ mysql对象调用了第一个错误,它刚刚尝试连接(看看meekrodb.php文件,看看我在谈论什么因此,这些错误可能与连接信息不良或连接到数据库的其他问题有关,因此其他功能失败。
查看更多信息性错误的一种简单方法是尝试使用他们的$throw_exception_on_error
函数:
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.
DB::$error_handler = false; // since we're catching errors, don't need error handler
DB::$throw_exception_on_error = true;
try {
$results = DB::QUERY("SELECT email FROM users WHERE email = %s", $email);
} catch(MeekroDBException $e) {
echo "Error: " . $e->getMessage() . "<br>\n"; // this should be a better error...
echo "SQL Query: " . $e->getQuery() . "<br>\n"; // SELECT email FROM users...
}
...
答案 1 :(得分:0)
如果这是include / include_once的问题,您将获得完全不同的消息。我首先建议使用2.3的最新版本的库,最重要的是,检查您正在使用的PHP版本。
据我所知,MySQLi连接很可能存在问题,并且根据您的PHP版本,确保连接没有失败的检查发生了此页面上的问题{{3} }
警告 mysqli-&gt; connect_error属性仅在PHP 5.2.9和5.3.0版本中正常工作。如果需要与早期PHP版本的兼容性,请使用mysqli_connect_error()函数。
由于没有连接,这将导致您在此表单中看到多个警告。
警告:mysqli :: method_name ():无效的对象或资源mysqli