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

Akshay Hazari
  • 3,186
  • 4
  • 48
  • 84
Rishabh Gupta
  • 73
  • 4
  • 13

1 Answers1

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);
});
Thamilhan
  • 13,040
  • 5
  • 37
  • 59