# Fatal error: Uncaught ArgumentCountError: mysqli\_real\_escape\_string() expects exactly 2 arguments, 1

**URL:** <https://www.phphelp.com/t/fatal-error-uncaught-argumentcounterror-mysqli-real-escape-string-expects-exactly-2-arguments-1/34547>\
**Category:** General PHP Help\
**Created:** [March 3, 2022, 12:34am UTC](https://www.phphelp.com/t/fatal-error-uncaught-argumentcounterror-mysqli-real-escape-string-expects-exactly-2-arguments-1/34547 "2022-03-03T00:34:13Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![janus](https://www.phphelp.com/user_avatar/www.phphelp.com/janus/32/4023_2.png) [@janus](https://www.phphelp.com/u/janus)\
**Post date:** [March 3, 2022, 12:34am UTC](https://www.phphelp.com/t/fatal-error-uncaught-argumentcounterror-mysqli-real-escape-string-expects-exactly-2-arguments-1/34547/1 "2022-03-03T00:34:13Z")

</div>

Hi All, I’m trying to get a php script to work in php8.0 (it was working in php5.6)  
One of tha last errors is `Fatal error: Uncaught ArgumentCountError: mysqli_real_escape_string() expects exactly 2 arguments, 1`

It comes from `if (isset($_GET['name'])) $qname="AND u.name LIKE '%".mysqli_real_escape_string ($_GET['name'])."%'";`

I already tried `($this->link, $_GET['name'])` but that gives the error that you can’t use $this on that place.  
Who can help me?  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![benanamen](https://www.phphelp.com/user_avatar/www.phphelp.com/benanamen/32/287_2.png) [@benanamen](https://www.phphelp.com/u/benanamen)\
**Post date:** [March 3, 2022, 12:56am UTC](https://www.phphelp.com/t/fatal-error-uncaught-argumentcounterror-mysqli-real-escape-string-expects-exactly-2-arguments-1/34547/2 "2022-03-03T00:56:10Z")

</div>

Look at the free manual for that function and it will show you exactly what is needed.

---

<div class="post-metadata">

**Author:** ![janus](https://www.phphelp.com/user_avatar/www.phphelp.com/janus/32/4023_2.png) [@janus](https://www.phphelp.com/u/janus)\
**Post date:** [March 3, 2022, 5:25pm UTC](https://www.phphelp.com/t/fatal-error-uncaught-argumentcounterror-mysqli-real-escape-string-expects-exactly-2-arguments-1/34547/3 "2022-03-03T17:25:07Z")

</div>

If I had found the answer in the Manuel I didn’t ask it here, but thanks for your response.

---

<div class="post-metadata">

**Author:** ![benanamen](https://www.phphelp.com/user_avatar/www.phphelp.com/benanamen/32/287_2.png) [@benanamen](https://www.phphelp.com/u/benanamen)\
**Post date:** [March 3, 2022, 5:50pm UTC](https://www.phphelp.com/t/fatal-error-uncaught-argumentcounterror-mysqli-real-escape-string-expects-exactly-2-arguments-1/34547/4 "2022-03-03T17:50:18Z")

</div>

It’s right on the page under “Parameters” and tells you what the two arguments the function expects.

Under procedural examples it shows a code example with the two arguments.

[https://www.php.net/manual/en/mysqli.real-escape-string.php](https://www.php.net/manual/en/mysqli.real-escape-string.php)

---

<div class="post-metadata">

**Author:** ![janus](https://www.phphelp.com/user_avatar/www.phphelp.com/janus/32/4023_2.png) [@janus](https://www.phphelp.com/u/janus)\
**Post date:** [March 3, 2022, 7:49pm UTC](https://www.phphelp.com/t/fatal-error-uncaught-argumentcounterror-mysqli-real-escape-string-expects-exactly-2-arguments-1/34547/5 "2022-03-03T19:49:32Z")

</div>

My bad I was inspecting help on phphelp not a a link to the manual.  
You can remove this topic I will try to find answers elsewhere.

---

<div class="post-metadata">

**Author:** ![benanamen](https://www.phphelp.com/user_avatar/www.phphelp.com/benanamen/32/287_2.png) [@benanamen](https://www.phphelp.com/u/benanamen)\
**Post date:** [March 4, 2022, 2:59am UTC](https://www.phphelp.com/t/fatal-error-uncaught-argumentcounterror-mysqli-real-escape-string-expects-exactly-2-arguments-1/34547/6 "2022-03-04T02:59:41Z")

</div>

You got help and were told exactly where the answer is along with a code sample. If you expect to be spoon feed answers your not going to make it very far as a programmer.

---

<div class="post-metadata">

**Author:** ![janus](https://www.phphelp.com/user_avatar/www.phphelp.com/janus/32/4023_2.png) [@janus](https://www.phphelp.com/u/janus)\
**Post date:** [March 4, 2022, 7:22am UTC](https://www.phphelp.com/t/fatal-error-uncaught-argumentcounterror-mysqli-real-escape-string-expects-exactly-2-arguments-1/34547/7 "2022-03-04T07:22:37Z")

</div>

That answer is not working for me, therefor I ask help here.  
I and just want to edit one php script and have no intention to become a php programmer.

---

<div class="post-metadata">

**Author:** ![phdr](https://www.phphelp.com/letter_avatar_proxy/v4/letter/p/91b2a8/32.png) [@phdr](https://www.phphelp.com/u/phdr)\
**Post date:** [March 4, 2022, 7:51am UTC](https://www.phphelp.com/t/fatal-error-uncaught-argumentcounterror-mysqli-real-escape-string-expects-exactly-2-arguments-1/34547/8 "2022-03-04T07:51:38Z")

</div>

> [@janus](#):
>
> have no intention to become a php programmer

As soon as you open a php file with a programming editor and type a single character, you ARE a php programmer, responsible for what is in that file and what the meaning is of the characters you are typing, no matter how capable or how uninterested you are in the subject 😁

The mysqli real\_escape\_string function (and several more primary mysqli statements) requires the mysqli connection as a parameter. Your task would be to identify what php variable is holding the msyqli connection and use it where it is needed. Since we don’t know what that variable is, and since this is a fairly obvious task, we cannot help you beyond pointing you in the direction of the documentation that defines the requirements for the function you are trying to make work.

---

<div class="post-metadata">

**Author:** ![janus](https://www.phphelp.com/user_avatar/www.phphelp.com/janus/32/4023_2.png) [@janus](https://www.phphelp.com/u/janus)\
**Post date:** [March 4, 2022, 8:45am UTC](https://www.phphelp.com/t/fatal-error-uncaught-argumentcounterror-mysqli-real-escape-string-expects-exactly-2-arguments-1/34547/9 "2022-03-04T08:45:58Z")

</div>

> I already tried `($this->link, $_GET['name'])` but that gives the error that you can’t use $this on that place.

$this-\>link is the connection variable  
from ` $this-\>link = mysqli\_connect($this-\>host, $this-\>user, $this-\>pass, $this-\>db);

I also tried $db-\>link, $\_GET[‘name’]) but that also don’t work.`

---

<div class="post-metadata">

**Author:** ![phdr](https://www.phphelp.com/letter_avatar_proxy/v4/letter/p/91b2a8/32.png) [@phdr](https://www.phphelp.com/u/phdr)\
**Post date:** [March 4, 2022, 6:11pm UTC](https://www.phphelp.com/t/fatal-error-uncaught-argumentcounterror-mysqli-real-escape-string-expects-exactly-2-arguments-1/34547/10 "2022-03-04T18:11:40Z")

</div>

> [@janus](#):
>
> $this-\>link is the connection variable

That’s an OOP class property. Accessing it inside of an instance of its class would use $this-\>link. To access it outside of an instance of its class, which is where the mysqli\_real\_escape\_string call is at, would require knowing what variable is holding the instance of that class.

Also, these type of database class ‘wrappers’ are usually just a bunch of code for nothing, that don’t help simplify writing applications.

At this point, it would take having all the relevant code in order to help you. It may be that the amount of changes, beyond fixing the current error, to make this work, is much more than to simply rewrite the database code using best practices.

BTW - using mysqli\_real\_escape\_string only provides protection for string data types and only if you have set the character set that php is using to match your database tables (this point is mentioned in the ‘caution’ statement in the mysqli\_real\_escape\_string documentation.) It provides no protection for numerical data types. The best method for providing protection for all data types is to use prepared queries, which actually simplifies converting old code, because it eliminates the need to use escape string functions and it simplifies the sql query syntax. Unfortunately, prepared queries using the mysqli extension are overly complicated and require you to essentially learn two different sets of statements. It is better and much simpler to convert code to use the PDO database extension instead.

---

<div class="post-metadata">

**Author:** ![janus](https://www.phphelp.com/user_avatar/www.phphelp.com/janus/32/4023_2.png) [@janus](https://www.phphelp.com/u/janus)\
**Post date:** [March 4, 2022, 6:45pm UTC](https://www.phphelp.com/t/fatal-error-uncaught-argumentcounterror-mysqli-real-escape-string-expects-exactly-2-arguments-1/34547/11 "2022-03-04T18:45:45Z")

</div>

Ok thanks, than I stop with it and try to find a other solution, thanks for your answer.
