[Solved] PHP Error: Mysqli_real_escape_string() expects exactly 2 parameters, 1 given

if (phpversion() >= '4.3.0'){
    $string = mysqli_real_escape_string($string);
    $string = mysqli_escape_string($string);

All the documentation for mysqli_real_escape_string seems to indicate this is a valid bit of code – don’t understand?

Solution #1:

Documentation saying two parameters: string mysqli_real_escape_string ( mysqli $link , string $escapestr ).

The first one is a link for a mysqli instance, the second one is the string to escape.

Respondent: meze

Solution #2:

Following is the proper format to use it :

string mysqli_real_escape_string ( mysqli $link , string $escapestr )

first parameter is mysql connection link identifier, and second is string
For more details, you can visit this link :

Respondent: Nishu Tayal

Solution #3:

Let me just add an extra bit of information:
If you are using NetBeans, its documentation actually shows the mysqli_real_escape_string
function like this:

mysqli_real_escape_string (PHP 5)
    Escapes special characters in a string for use in an SQL statement, taking into account the current charset of the connection


    string $escapestr
        'The string to be escaped.'



    an escaped string.

This is wrong, though, as shown in the other answers. It requires both the $link and the $string.

Respondent: Pedro Moreira

Solution #4:

$con = new mysqli("localhost", "root", "your_password", "your_database_name");
$data = json_decode(file_get_contents("php://input"));
$empno = mysqli_real_escape_string($con, $data->empno);//this will do your work
Respondent: Israel Meshileya

Solution #5:

mysqli_real_escape_string(DBconnection, __dat__a);
mysqli_real_escape_string needs the db connection variable

Respondent: learningjoe

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy