-1

Im trying to convert my Wordpress theme from PHP 5.4 to 7.1

But... I still don't understand what's happening with this error :

Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in /home/myhost/wp-content/themes/mytheme/functions.php on line 69

$con = new mysqli('localhost', 'my_user', 'my_password', 'my_db');


function cG($name){
    if(get_magic_quotes_gpc()) $_GET[$name]=stripslashes($_GET[$name]); 
    $name=mysqli_real_escape_string($con, $_GET[$name]);
    return $name;
}

I tried to follow this, but even I get the error... Any idea ? Thank you!

azjezz
  • 3,827
  • 1
  • 14
  • 35
hiloes
  • 25
  • 1
  • 4

1 Answers1

0

magic_quotes_gpc is deprecated as of PHP 5.3 and removed as of PHP 5.4 ... so your check here is useless ... And keep in mind that your connection string isn't visible inside the function, You'll either have to accept it as an argument or use global keyword which isn't a good solution.

Accepting as an arugment:

function cG($con, $name){
    $name=mysqli_real_escape_string($con, $_GET[$name]);
    return $name;
}

cG($con, 'something');

or using global keyword:

function cG($name){
    global $con;
    $name=mysqli_real_escape_string($con, $_GET[$name]);
    return $name;
}
ahmad
  • 2,709
  • 1
  • 23
  • 27