Question

I am novice in PHP and trying to make register form onclick of submit button i have used action which will process the user's enter details means username length and password length but this function is not being called onclick of submit button my browser is showing me whole code whatever i have written in "SignUp.php" page.Can someone pls help me...... InternHtml.php code

    <div id="wrapper" class="wrapperClass">
   <fieldset>
            <legend class="regLagendClass">Registration Form</legend>
    <form id="registrationForm" method="POST" action="SignUp.php">
           <!-- <form id="registrationForm" method="get" action="">-->
            <div class="divClass">
                <label for="firstName" class="labelClass">First Name:</label>
                <input type="text"  name="fName" class="textboxClass" id="firstName" placeholder="Your First Name"/>
            </div>

            <div class="divClass">
                <label for="lastName" class="labelClass">Last Name:</label>
                <input type="text" name="lName" id="lastName" class="textboxClass" placeholder="Your Last Name"/>
            </div>
 <div class="divClass">
                <label for="userName" class="labelClass">User Name:</label>
                <input type="text" name="userName" id="userName" class="textboxClass" placeholder="Your User Name" required/>
            </div>

            <div class="divClass">
                <label for="password" class="labelClass">Password:</label>
                <input type="password" id="password" name="password" class="textboxClass" placeholder="Type Password" required/>
            </div>
 <div class="divClass">
                <label for="cPassword" class="labelClass">Confirm Password:</label>
                <input type="password" id="cPassword" name="userPassword" class="textboxClass" placeholder="Retype Password"/>
            </div>

            <div class="divClass">
                <label for="gender" class="labelClass">Choose Gender:</label>
                <select name="gender" class="textboxClass">
                    <option>Male</option>
                    <option>Female</option>
                </select>
            </div>

            <div class="divClass">
                <label class="labelClass" for="dob">Date of Birth:</label>
                <input type="date" id="dob" class="textboxClass" placeholder="Your Date of Birth"/>
            </div>
            <div class="divClass">
               <!-- <label for="country" class="labelClass">Country:</label>
                <input type="text"  id="country" class="textboxClass"/>-->
                <label for="emailId" class="labelClass">Email Id:</label>
                <input type="email"  id="emailId" name="userEmail" class="textboxClass"/>
            </div>

            <div class="divClass">
                <input type="submit" value="Sign Up"/>
            </div>
</form>
</fieldset>
</div>

SignUp.php Code

 function registerFunction()
{
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $uname = $_POST['userName'];
    $pword = $_POST['password'];
   $errorMessage;
    $uname = htmlspecialchars($uname);
    $pword = htmlspecialchars($pword);
    $uLength = strlen($uname);
    $pLength = strlen($pword);
    if($uLength >= 0 && $uLength <= 10)
    {
    $errorMessage = "UserName Length";
    }
    else
    {$errorMessage = "No error in UserName Length";
    }
    if($pLength >= 0 && $pLength <= 10)
    {
    $errorMessage = "password Length";
    }
    else
    {$errorMessage = "No error in password Length";
    }
    if(strlen($errorMessage) == "")
    {
    echo "There is no error::::NO Error Message" .$errorMessage;
    }
    else
    {
    echo "There is error::::Error Message" .$errorMessage;
    }

}
}
Was it helpful?

Solution

First of all you are not at all calling your registerFunction() anywhere ..

Just rewrite your SignUp.php like this

<?php

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $uname = $_POST['userName'];
    $pword = $_POST['password'];
    $errorMessage;
    $uname = htmlspecialchars($uname);
    $pword = htmlspecialchars($pword);
    $uLength = strlen($uname);
    $pLength = strlen($pword);
    if($uLength >= 0 && $uLength <= 10)
    {
        $errorMessage = "UserName Length";
    }
    else
    {$errorMessage = "No error in UserName Length";
    }
    if($pLength >= 0 && $pLength <= 10)
    {
        $errorMessage = "password Length";
    }
    else
    {$errorMessage = "No error in password Length";
    }
    if(strlen($errorMessage) == "")
    {
        echo "There is no error::::NO Error Message" .$errorMessage;
    }
    else
    {
        echo "There is error::::Error Message" .$errorMessage;
    }
}

OTHER TIPS

You need to call registerFunction() function SignUp.php

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top