I try make php login but i get this error: Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given,
what I do wrong?
register.php
Replace your query with the following:
$query = mysql_query("INSERT INTO users VALUES('$username','$pass','$email')", `$Connect`);
you are mixing mysql
and mysqli
use this mysql_real_escape_string
like
$username = mysql_real_escape_string($_POST['username']);
NOTE : mysql_*
is deprecated use mysqli_*
or PDO
mysqli_real_escape_string function requires the connection to your database.
$username = mysqli_real_escape_string($your_connection, $_POST['username']);
P.S.: Do not mix mysql_ functions* and mysqli_ functions*. Please use mysqli_* functions or PDO
because mysql_* functions are deprecated and will be removed in the future.
From the documentation , the function mysqli_real_escape_string()
has two parameters.
string mysqli_real_escape_string ( mysqli $link , string $escapestr ).
The first one is a link for a mysqli instance (database connection object), the second one is the string to escape. So your code should be like :
$username = mysqli_real_escape_string($yourconnectionobject,$_POST['username']);
use mysql_real_escape_string()
instead of mysqli_real_escape_string()
like so:
$username = mysql_real_escape_string($_POST['username']);
You are mixing mysqli
and mysql
function.
If your are using mysql function then instead mysqli_real_escape_string($your_variable);
use
$username = mysql_real_escape_string($_POST['username']);
$pass = mysql_real_escape_string($_POST['pass']);
$pass1 = mysql_real_escape_string($_POST['pass1']);
$email = mysql_real_escape_string($_POST['email']);
If your using mysqli_* function then you have to include your connection to database into mysqli_real_escape function :
$username = mysqli_real_escape_string($your_connection, $_POST['username']);
$pass = mysqli_real_escape_string($your_connection, $_POST['pass']);
$pass1 = mysqli_real_escape_string($your_connection, $_POST['pass1']);
$email = mysqli_real_escape_string($your_connection, $_POST['email']);
Note : Use mysqli_* function since mysql has been deprecated. For information please read mysqli_*