-3

i have code like this but when i click submit its give me error mysqli_real_escape_string() expects parameter 2 to be string, array given where should i do or put the mysqli_real_escape_string ?

if(!empty($_POST['poscon'])) {
        foreach($_POST['poscon'] as $condition) 
            $condition=mysqli_real_escape_string($link,$_POST['poscon']);
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85

2 Answers2

0

Seeing you're not responding to comments, I'm posting this as an answer.
- Maybe you'll respond then.

You see your foreach($_POST['poscon'] as $condition)?

You're using the wrong parameter and passing the array instead of the $condition variable.

Do $condition=mysqli_real_escape_string($link,$condition);

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • Please give me example before `mysqli_real_escape_string` and after the string which gets generated. As it casuse confusion and no example is given. – Pratik Joshi Dec 12 '15 at 14:08
  • @PratikCJoshi Given that the OP did not supply anything else in their question, I won't be able to provide you with that information, other than visiting the PHP.net's website on the function http://php.net/manual/en/mysqli.real-escape-string.php and tutorials site. – Funk Forty Niner Dec 12 '15 at 14:28
  • Hi Fred, there is NO input and output after using the function. And I checked Lots of answers here but nothing gave me output after applying function. Maybe you can supply us answer! – Pratik Joshi Dec 12 '15 at 14:32
  • @PratikCJoshi you need to post a question about this. Stack doesn't approve about responding to questions for someone else. Sorry, but that's how Stack works. – Funk Forty Niner Dec 12 '15 at 14:34
0

When ever you taking user inputs from the view you should check.

mysqli_real_escape_string Definition

This function is used to create a legal SQL string that you can use in an SQL statement. The given string is encoded to an escaped SQL string, taking into account the current character set of the connection.

mysqli_real_escape_string Manual

  1. Normal text

    Early `$name = $_POST['name'];`        
    New Practice `$name = mysqli_real_escape_string($_POST['name'])`
    
  2. URL

    Early `$url = $_POST['url'];`        
    New Practice `FILTER_VALIDATE_URL` [Check Example](http://www.w3schools.com/php/filter_validate_url.asp)
    
  3. E-Mail

    Early `$email = $_POST['email'];`        
    New Practice `FILTER_VALIDATE_EMAIL` [Check Example](http://www.w3schools.com/php/filter_validate_email.asp)
    

More Useful Articles

  1. Is mysqli_real_escape_string safe?
  2. mysql(i)_real_escape_string, safe to rely on?
  3. mysqli::real_escape_string, mysqli_real_escape_string
Community
  • 1
  • 1
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85