-1

EDIT:

Hi I am trying to build a form and check if the email address is already taken during the sign up process. Currently I am trying this on my localhost. But whenever I sign up it says

Could not sign up.

Where am I mistaking? PHP code:

<?php
if (array_key_exists("submit", $_POST)) {

    $link = mysqli_connect("localhost", "root", "root", "form");
    if (mysqli_connect_error()) {

        die ("Database Connection Error");

    }
    else {
        $query = "SELECT id FROM 'users' WHERE email = '".mysqli_real_escape_string($link, $_POST['email'])."' LIMIT 1";
        $result = mysqli_query($link, $query);
        if (mysqli_num_rows($result) > 0) {
           echo  "That email address is taken.";
        }
        else {
            $query = "INSERT INTO 'users' ('name', 'email', 'password', 'number') VALUES ('".mysqli_real_escape_string($link, $_POST['name'])."', '".mysqli_real_escape_string($link, $_POST['email'])."', '".mysqli_real_escape_string($link, $_POST['password'])."', '".mysqli_real_escape_string($link, $_POST['number'])."')";
            if (!mysqli_query($link, $query)) {
                echo  "Could not sign up.";
            }
            else {
                echo "Sign up successful.";
            }
        }
    }
}
?>
Kumar Priyansh
  • 68
  • 2
  • 10

1 Answers1

0

You're using single quotes to delimit field and table names when you should be using back ticks. If you're unable to use back ticks, just omit them altogether - MySQL field and table names are case insensitive by default.

E.g.:

$query = "INSERT INTO users (name, email, password, number) VALUES ...
e_i_pi
  • 4,590
  • 4
  • 27
  • 45