$username = $_POST['username']; $query = "SELECT COUNT(*) FROM users WHERE username='$username'"; $result = mysqli_query($conn, $query); if(mysqli_num_rows($result) > 0) { echo "Sorry, this username already exists!"; }
$email = $_POST['email']; $query = "SELECT COUNT(*) FROM users WHERE email='$email'"; $result = mysqli_query($conn, $query); if(mysqli_num_rows($result) > 0) { echo "Sorry, this email address already exists!"; }Package Library: The package library for the "user exists" function in PHP could be any database package, such as MySQL, PostgreSQL, Oracle, Microsoft SQL Server, etc. The examples above use the mysqli_query() function, which is a part of the MySQLi extension in PHP.