我已经搜索并尝试了 Stakeoverflow 向我提出的所有建议,但没有一个对我有用。我有 2 个 php 文件(add_new_page.php、sanitise.php)我在“sanitise.php”函数“escape”上收到此错误。
PHP - 调用未定义的方法数据库::real_escape_string()
我似乎无法找出我在函数转义中做错了什么。任何帮助将不胜感激。我的最后期限非常接近,我需要尽快完成这项工作。以下是我的 2 个工作文件的代码。
数据库连接
$db = new database($db_host, $db_user, $db_pass, $db_name);
add_new_page.php
require_once "../classes/classes.php";
if(isset($_POST["txtpagetitle"])){
$txtpagetitle = $_POST["txtpagetitle"];
$txtbrowsertitle = $_POST["txtbrowsertitle"];
$txtpagecontent = $_POST["txtpagecontent"];
$txtpagetitle = trimmer($txtpagetitle);
$txtbrowsertitle = trimmer($txtbrowsertitle);
$txtbrowsertitle = trimmer($txtbrowsertitle);
$txtpagetitle = escape($txtpagetitle, $db);//Calling escape function
$txtbrowsertitle = escape($txtbrowsertitle, $db);//Calling escape function
$txtbrowsertitle = escape($txtbrowsertitle, $db);//Calling escape function
$txtpagetitle_required = required($txtpagetitle);
$txtbrowsertitle_required = required($txtbrowsertitle);
if($txtpagetitle_required == false){
echo "Page Title is required...";
return false;
}
}
清理.php
// Escape all characeters - I' am getting the error here...
function escape($field){
global $db;
return $db->real_escape_string($field);
}