PHP sign up form Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of PHP sign up form without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I’m new in PHP so I have trouble with make simple sign up form. My issue is that when I would like to sign up every data is send to my db except password. Where is the error?

My db is mySQL. Try few times user_pwd has no output in my db…

php singup form:

<form class="signup-form" action="includes/signup.inc.php" method="POST">
            <input type="text" name="first" placeholder="Name">
            <input type="text" name="last" placeholder="Surname">
            <input type="text" name="email" placeholder="E-mail">
            <input type="text" name="uid" placeholder="ID">
            <input type="password" name="pwd" placeholder="Password">
            <button type="submit" name="submit">Sing up</button>
        </form>

php – singup.inc.php:

<?php


if(isset($_POST['submit'])){
    include_once 'db.php';

    $first = mysqli_real_escape_string($conn,$_POST['first']);
    $last = mysqli_real_escape_string($conn,$_POST['last']);
    $email = mysqli_real_escape_string($conn,$_POST['email']);
    $uid = mysqli_real_escape_string($conn,$_POST['uid']);
    $pwd = mysqli_real_escape_string($conn,$_POST['pwd']);
    // error handlers
    // all fields not empty
    if(empty($first) || empty($last) || empty($email) || empty($uid) || empty($pwd) ){
        header("Location: ../signup.php?signup=empty");
        exit();
    }
    else{
        // check spelling
        if(!preg_match("/^[a-zA-z]*$/", $first) || !preg_match("/^[a-zA-z]*$/", $last)){
            header("Location: ../signup.php?signup=invalid");
        exit();
        }
        else{
            if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
        header("Location: ../signup.php?signup=email");
        exit();
            }
            else{
                $sql = "SELECT * FROM users WHERE user_uid = '$uid'";
                $result = mysqli_query($conn, $sql);
                $resultCheck = mysqli_num_rows($result);
                if($resultCheck>0){
                    header("Location: ../signup.php?signup=usertaken");
                    exit();
                }else{
                    $hashedPwd = password_hash($pwd, PASSWORD_DEFALUT);
                    $sql = "INSERT INTO users (user_first, user_last, user_email, user_uid, user_pwd) VALUES ('$first', '$last', '$email', '$uid', '$hashedPwd');";
                    mysqli_query($conn, $sql);
                    header("Location: ../signup.php?signup=success");
                    exit();
                }
            }
        }
    }
}
else{
    header("Location: ../signup.php");
    exit();
}

Answer

taken from: http://php.net/manual/en/function.password-hash.php

Return Values ΒΆ

Returns the hashed password, or FALSE on failure.

you have

$hashedPwd = password_hash($pwd, PASSWORD_DEFALUT);

which most likely returns “false”, because it doesn’t support the hash mode “PASSWORD_DEFALUT”.

Try editing that to the correct format

$hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);

I hope that solves it for you.

We are here to answer your question about PHP sign up form - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji