How can I insert a new record if an email is correct?

This is my code:



    <title>PHP login system</title>

    <link rel = "stylesheet" type = "text/css" href = "style.css">   



    <div id = "frm">  


        <form name="f1" action = "authentication.php" onsubmit = "return validation()" method = "POST">  


                <label> UserName: </label>  

                <input type = "text" id ="user" name  = "user" />  



                <label> Password: </label>  

                <input type = "password" id ="pass" name  = "pass" />  



                <input type =  "submit" id = "btn" value = "Login" />  






            function validation()  


                var id=document.f1.user.value;  

                var ps=document.f1.pass.value;  

                if(id.length=="" && ps.length=="") {  

                    alert("User Name and Password fields are empty");  

                    return false;  




                    if(id.length=="") {  

                        alert("User Name is empty");  

                        return false;  


                    if (ps.length=="") {  

                    alert("Password field is empty");  

                    return false;  









    $host = "localhost";  

    $user = "adminko";  

    $password = 'root';  

    $db_name = "practice_schema";  


    $con = mysqli_connect($host, $user, $password, $db_name);  

    if(mysqli_connect_errno()) {  

        die("Failed to connect with MySQL: ". mysqli_connect_error());  






    $username = $_POST['user'];  

    $password = $_POST['pass'];  


        //to prevent from mysqli injection  

        $username = stripcslashes($username);  

        $password = stripcslashes($password);  

        $username = mysqli_real_escape_string($con, $username);  

        $password = mysqli_real_escape_string($con, $password);  


        $sql = "select *from login where username = '$username' and password = '$password'";  

        $result = mysqli_query($con, $sql);  

        $row = mysqli_fetch_array($result, MYSQLI_ASSOC);  

        $count = mysqli_num_rows($result);  


        if($count == 1){  

            echo "<h1><center> Login successful </center></h1>";  



            echo "<h1> Login failed. Invalid username or password.</h1>";  



Hi @idontknowphp

Somewhere in your code you need to issue an INSERT query… probably in a new file call signup.php or similar.


Sponsor our Newsletter | Privacy Policy | Terms of Service