I'm making a user registration for my first-ever database drive app and I've encountered a problem that I can't fix since last night. First, there was a problem with the DB connection which is now fixed (doesn't give any errors).
There might be something wrong with my code here, that I really can't find out.
<?php
include ("db.php");
if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['email']) )
{
// prevent SQL injections
$username = mysqli_real_escape_string ($_POST ['username']);
$email = mysqli_real_escape_string ($_POST['email']);
// md5 hash of password
$password = md5 ($_POST['password']);
// check to see if username exists
$sql = mysqli_query ("SELECT username FROM users WHERE username = '".$username."'");
if (mysqli_num_rows($username>0))
{
die ("Username taken.");
}
$insert_user = mysqli_query ("INSERT INTO users (username, password, email) VALUES ( '$username', '$password', '$email')") or die ("Error"); echo "Account Created.";
}
There errors are these:
Quote
Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in C:\path\register.php on line 11
Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in C:\path\register.php on line 12
Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\path\register.php on line 20
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\path\register.php on line 22
Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\path\register.php on line 27
Error
Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in C:\path\register.php on line 12
Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\path\register.php on line 20
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\path\register.php on line 22
Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\path\register.php on line 27
Error
Please note that I am quite a novice in PHP and I have trouble figuring errors out.
Thanks for you help, in advance.

New Topic/Question
Reply




MultiQuote





|