user1650817
user1650817

Reputation:

PHP - Call to undefined method database::real_escape_string()

I have searched and tried all the suggestions that Stakeoverflow suggested to me, But none was working for me. I have 2 php files (add_new_page.php, sanitise.php) I' am getting this error on "sanitise.php" function "escape".

PHP - Call to undefined method database::real_escape_string()

I can't seem to find out what I' am doing wrong in my function escape. Any help will be really appreciated. My deadlines are very close and I need to get this working soon as possible. Below are the codes of my 2 working files.

Database Connection

$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;
        }       
}

sanitise.php

// Escape all characeters - I' am getting the error here...
    function escape($field){
        global $db;
        return $db->real_escape_string($field);
    }

Upvotes: 0

Views: 1496

Answers (1)

Dylan
Dylan

Reputation: 580

The type 'database' does not contain a function called 'real_escape_string'. I have a theory that you're using this because you're used to MySQLi which has a function $db->real_escape_string(). Maybe your (or whoever wrote it) 'database' class has an equivalent function with a different name. Otherwise, there is no real_escape_string function in $db to be called.

Upvotes: 1

Related Questions