Check if email already exist
<p>How do I check if the email already exist in the database and deny the registration?</p>

<p>MySQL was the one taught to me and I'm currently on a wall using MySQLi.</p>

<p>Here is the code that I'm currently working on using MySQLi: </p>

<pre><code>&lt;?php 
$cookie_name = "loggedin";

$servername = "localhost";
$username = "root";
$password = "";
$database = "scholarcaps";
$conn = mysqli_connect($servername, $username, $password, $database);

if (!$conn) {
    die("Database connection failed: ".mysqli_connect_error());
}

if (isset($_POST['login']))
{
    $user = $_POST['username'];
    $pass = $_POST['password'];

    $phash = sha1(sha1($pass."salt")."salt");

    $sql = "SELECT * FROM users WHERE username='$user' AND password='$phash';";

    $result = mysqli_query($conn, $sql);
    $count = mysqli_num_rows($result);

    if ($count == 1)
    {
        $cookie_value = $user;
        setcookie($cookie_name, $cookie_value, time() + (180), "/");
        header("Location: personal.php");
    }
    else
    {
        echo "Username or password is incorrect!";
    }
}
else if (isset($_POST['register']))
{
    $user = $_POST['username'];
    $email = $_POST['email'];
    $pass = $_POST['password'];

    $phash = sha1(sha1($pass."salt")."salt");

    $sql = "INSERT INTO users (id, email, username, password) VALUES ('','$email', '$user', '$phash');";

    $result = mysqli_query($conn, $sql);
}
?&gt;
</code></pre>