1
$sql="select * from question_test where test_id='".$test_id."'   and  difficulty_level   BETWEEN  ".$_SESSION['difficulty_start']." and  ".$_SESSION['difficulty_end']." and question_id NOT IN ('".implode("', '", array_map('mysqli_real_escape_string', $_SESSION['question_attempt']))."')  order by rand()*favourability_level  desc";

On running the above code I get an error :

Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in C:\xampp\htdocs\exam.php on line 359

1 Answer 1

1

Use a callback function instead

function array_map_callback($a)
{
  global $con;
  return mysqli_real_escape_string($con, $a);
}

array_map('array_map_callback', $_SESSION['question_attempt']);

where $con is the connection variable.

So your $sql variable would be:

$sql="select * from question_test where test_id='".$test_id."' and  difficulty_level BETWEEN  ".$_SESSION['difficulty_start']." and  ".$_SESSION['difficulty_end']." and question_id NOT IN ('".implode("', '", array_map('array_map_callback', $_SESSION['question_attempt']))."')  order by rand()*favourability_level  desc";

or you can go with array_walk

array_walk($_SESSION['question_attempt'], function(&$string) use ($con) { 
  $string = mysqli_real_escape_string($con, $string);
});
Sign up to request clarification or add additional context in comments.

3 Comments

Or array_map(function($a) use($con) { ...}, $_SESSION['question_attempt']).
@Sougata wow.. I was adding that to my answer and you commented!
Thanks a lot , you saved my sanity , I had brooded over this for entire last day .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.