-1

Here is my code:

include "db_conx.php";
$sql = mysqli_query("INSERT INTO table(column) VALUES('" . mysqli_real_escape_string($var) . "')");
if ($sql) {echo "connection successful";
} else {
echo "failure";
}

It returns these errors:

Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given
Warning: mysqli_query() expects at least 2 parameters, 1 given

I tried using PDO but that didn't work either...

3 Answers3

0

First Parameter is mysql connection link identifier, and second is string For more details, you can visit this link : http://in2.php.net/manual/en/mysqli.real-escape-string.php.

include "db_conx.php";
$sql = mysqli_query(pass_your_connection_identifier_here ,"INSERT INTO table(column) VALUES('" . mysqli_real_escape_string(pass_your_connection_identifier_here, $var) . "')");
if ($sql) {echo "connection successful";
} else {
echo "failure";
}
Ankur Tiwari
  • 2,762
  • 2
  • 23
  • 40
0

You are missing connection identifier in both mysqli_real_escape_string() and mysqli_query() change your code to mysqli_query($connection,$sql) and mysqli_real_escape_string($connection,$string)

Mujahidh
  • 428
  • 4
  • 19
0

You are missing connection variable at both the lines that's why you are facing issues :

Try to replace your code with this :

//$con // it is your connection variable
include "db_conx.php";
$sql = mysqli_query($con,"INSERT INTO table(column) VALUES('" . mysqli_real_escape_string($con,$var) . "')");
if ($sql) {echo "connection successful";
} else {
echo "failure";
}
Nehal
  • 1,542
  • 4
  • 17
  • 30