this is the code that i used:
<?php
$username = filter_input(INPUT_POST, 'username');
$password = filter_input(INPUT_POST, 'password');
if (!empty($username)){
if (!empty($password)){
$host = "localhost";
$dbusername = "root";
$dbpassword = "1234";
$dbname = "admin";
// Create connection
$conn = new mysqli ($host, $dbusername, $dbpassword, $dbname);
$dbunames = mysqli_query("SELECT * FROM entity WHERE username='$username'");
if (mysqli_num_rows($dbunames) > 0 ) { //check if there is already an entry
for that username
echo "Already taken";
}
else{
$sql = "INSERT INTO entity (username, password)
values ('$username','$password')";
if ($conn->query($sql)){
echo "New record is inserted sucessfully";
}
else{
echo "Error: ". $sql ."
". $conn->error;
}
$conn->close();
}
}
else{
echo "Password should not be empty";
die();
}
}
else{
echo "Username should not be empty";
die();
}
?>
and this is the error(in the web):
Warning: mysqli_query() expects at least 2 parameters, 1 given in
C:\xampp\htdocs\form\connect.php on line 15
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null
given in C:\xampp\htdocs\form\connect.php on line 19
New record is inserted sucessfully
i know "the record is inserted sucessfully" but the username is already taken validation is not working. i'm not good at php so i would be pleased if you tell me how to fix this code simply.
please help me!!!