Search code examples
phpmysqlregistration

Registration form validation error


This is my registration.php

include("config.php");

if(isset($_POST['submit'],$_POST['fullname'],$_POST['username'], $_POST['password'],         $_POST['email'], $_POST['role']))
{
    $submit=$_POST['submit'];
    $date=date("y-m-d");
    $fullname = mysql_real_escape_string($_POST['fullname']);
    $username = mysql_real_escape_string($_POST['username']);
    $password = md5(mysql_real_escape_string($_POST['password']));
    $email = mysql_real_escape_string($_POST['email']);
    $role = (int)$_POST['role'];

    if($submit)
    {
        if($fullname&&$username&&$password&&$email&&$emp_role)
        {

            $sql="INSERT INTO `logindetails` (fullname,username, password, email,     emp_role,$date) VALUES ('$fullname',$username', '$password','$email','$emp_role','$date')";

            $result=mysql_query($sql) or die(mysql_error());

            echo "<h1>you have registered sucessfully</h1>";

            echo "<a href='login.php'>go to login page</a>";

        }
        else
        {
            echo "Please fill in <b>all</b>fields!";
        }
    }
}

Are there any errors in this code? If I submit the form I'm not getting any message. Is this code right or is there anything I missed for validation?

I created table with id, username, password, date, role, fullname, email


Solution

  • You don't get any results maybe because some of your conditionals aren't true ... put an ending "else" condition for each if/else statement . You have 2 if/else conditionals that don't have any "else" ending condition.
    Here is where you missed else : if(isset(post[]) etc... ) { } and for the if($submit) {}

    If you would put an else condition to each if/else statement ( ex. : else { echo "condition failed" } ) i bet you would surely get a result