functions.php problem line 60

Hello, I am having a problem with Alaska Theme. Not sure if the problem is with the theme or on my server side of things. Problem I am having is:
Warning: mysqli_escape_string() expects exactly 2 parameters, 1 given in /home/enticingsolutions/domains/alaska.enticingsolutions.us/public_html/wp-content/themes/alaska/functions.php on line 60

At first the my site would not load at all until I changed msql_ to mysqli_
I am on PHP7. Also tried with different versions of wordpress with no luck.
now the page loads but the error stays visible on every page.

my current line 60 is:

if ( $wpdb->get_var('SELECT count(*) FROM ' . $wpdb->prefix . 'datalist WHERE url = "'.mysqli_escape_string( $_SERVER['REQUEST_URI'] ).'"') == '1' )
domain is http://alaska.enticingsolutions.us

Any help or guidence would be great.
Thank you
Jose

  • Adam Czajczyk
    • Support Gorilla

    Hello Jose,

    I hope you're well and thank you for your question!

    Do I understand correctly that you had to make changes to the theme itself to make it work? The "mysql" is no longer supported with PHP 7.x so that's why it didn't work but I admit I"m surprised that it's using direct calls to database at all. I don't have access to this theme to test it though, as it's a premium theme. I'll therefore refer only to the part of the code that you posted here :slight_smile:

    The "mysqli_escape_string" does indeed requires two parameters when it's used in "procedural style" the way it's in the posted code. There's actually a single parameter only and it's the one that should be used as a second one. The first one should be "$link" which is a "database handle".

    If you are using "mysqli_" function there should first be a connection to the database made by using "mysqli_connect()" or "mysql_init()" and both of these functions return a link to the database. A variable holding that link should be passed to the "mysqli_escape_string()" function as the first parameter. Take a look here please:

    http://php.net/manual/en/mysqli.real-escape-string.php

    A bit blind shot (because of no access to Alaska theme) but I think you should review the theme code against a line similar to this:

    $link = mysqli_connect()

    The "$link" may actually be a different variable but you should be able to identify it and then use it in your part of code for "mysqli_escape_string()" like this:

    = "'.mysqli_escape_string( $link, $_SERVER['REQUEST_URI'] ).'"') == '1' )

    If you have any additional questions let me know please.

    Kind regards,
    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.