0

Basically i am making a PHP signup script, but i am getting "SQL Failed" but all the details are correct

My code

$link = mysqli_connect("localhost", "username", "password");
$database = mysqli_select_db($link, "database");

$user = mysqli_real_escape_string($link, $_GET['username']);
$password = mysqli_real_escape_string($link, $_GET['password']);

$table = "login";

$sql = "SELECT * FROM " . $table . " WHERE username=?";
$stmt = mysqli_stmt_init($link);

if (!mysqli_stmt_prepare($stmt, $sql))
{
    echo "SQL Failed.";
} else {

    mysqli_stmt_bind_param($stmt, "s", $user);
    mysqli_stmt_execute($stmt);
    Signupuser($user, $password, $table, $link);
}

function Signupuser($user, $password, $table, $link)
{
    $options = ['cost' => 11];

    $hashedPassword = password_hash($password, PASSWORD_BCRYPT, $options);

    $sql = "INSERT INTO `" . $table . "` (username, password) VALUES (?, ?);";
    $stmt = mysqli_stmt_init($link);

    if (!mysqli_stmt_prepare($stmt, $sql))
    {
        echo "SQL Failed.";
    } else {

        mysqli_stmt_bind_param($stmt, "ss", $user, $hashedPassword);
        mysqli_stmt_execute($stmt);

        echo "User Created!";
    }
}

But it's going to SQL failed, but all the details are correct? Am i doing something wrong...?

Any help and or pointers would be great thanks!

0 Answers0