I want to check if a user has already been registered in the database to not have duplicate users, but when I use mysqli_num_rows to know if there is any line with that user the error of the title.
<?php
include("setting.php");
$user = $_GET['user'];
$pas = $_GET['pass'];
$check = "SELECT * FROM user WHERE name='$user'";
$sql = mysqli_query($mysqli, $check);
$ln = mysql_num_rows($sql);
if ($ln == 0) {
$code = "INSERT INTO users(id, name, pass, sp) VALUES (null, '$user', '$pass', 0)";
$query = $mysqli->query($code);
if ($query) {
header("location: ../index.php");
}
}else{
echo "Este usuario já existe";
}
?>
I was able to solve this by saying:
<?php
include("setting.php");
$user = $_GET['user'];
$pass = $_GET['pass'];
$sql = mysqli_query($mysqli, "SELECT * FROM user WHERE name='$user'");
$ln = mysqli_num_rows($sql);
if ($ln == 0) {
$query = mysqli_query($mysqli, "INSERT INTO user(id, name, pass, sp) VALUES(null, '$user', '$pass', 0)");
header("location: ../index.php");
}
?>