Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6324361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:41:19+00:00 2026-05-24T16:41:19+00:00

I am designing a registration form in php. i want to add some validation

  • 0

I am designing a registration form in php. i want to add some validation in my form. validations are related to require field validation. this is my code.

<?php
   include('connect.php');
    if(isset($_REQUEST['Register']))
    {

         $error='';//initialize $error to blank
  if(trim($_POST[userid])==''){
      $error.="Please enter a username!<br />"; //concatenate the $error Message with a line break 
  }
  if(trim($_POST[password])==''){
      $error.="Please Enter password! <br />";//concatenate more to $error  
  } 
  if(trim($_POST[email])=='')
  {
    $error.="Please Enter email address !<br />"; 
  }
  else
   {
        if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST[email])) { 
        $error="The e-mail you entered was not in the proper format!"; 

        }
    }
    if(trim($_POST[regAs])=='NULL')
  {
    $error.="Please select Register As !<br />"; 
  }

  if($error!='')
  {
    echo "<span style=color:red>$error</span>";
    //Hmmmm no text is in $error so do something else, the page has verified and the email was valid
    // so uncomment the line below to send the user to your own success page or wherever (swap  
     //yourpage.php with your files location). 
     //echo "script type=\"text/javascript\">window.location=\yourpage.php\"<script>";  
   }
   else
   {
           $userid=$_REQUEST['userid'];
        $name=$_REQUEST['name'];
       $password=$_REQUEST['password'];
       $repassword=$_REQUEST['repassword'];
       $email=$_REQUEST['email'];
       $regAs=$_REQUEST['regAs'];
       if($password!=$repassword)
        {
           echo "<script>alert('both are diferent password')</script>";
        }
       else
        {

         mysql_query("insert into login(userid,name,password,email,regAs)  values('$userid','$name','$password','$email','$regAs')");
        }   
   }                










    }
?>
<html>
<head></head>
<body>
<form action="" method="post" name="f">
<table align="center">
<tr>
<td>User ID :</td><td>
<input type="text" name="userid" value=""></td>
</tr>
<tr>
<td>Name :</td><td>
<input type="text" name="name" value=""></td>
</tr>
<tr>
<td>Password : </td>
<td><input type="password" name="password" value=""></td>
</tr>
<tr>
<td>Re-Enter Password : </td>
<td><input type="password" name="repassword" value=""></td>
</tr>
<tr>
<td>Email id :</td><td>
<input type="text" name="email" value=""></td>
</tr>
<tr>
<td>Register As :</td><td>
<select id="regAs" name="regAs">
<option value="NULL">SELECT</option>
<option value="Artist">Artist</option>
<option value="Buyer">Buyer</option>
</select></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="Register" value="Register"</td></tr>
</table>
</form>

</body>
</html>

and this is the out put screen to check validation. these error messages are coming at first line. But i want that error must come infrontof each line. for example if user does not enter email then error must show in front of email text box. please suggest me what should i do..?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:41:21+00:00Added an answer on May 24, 2026 at 4:41 pm

    Well if you want the errors to be in front of the correct form field, you will somehow have to get the errors at the right place in your HTML. The simplest solution would be to create a variable or an array node for each possible form field and insert an error message into it if necessary. I’ll give a short example:

    <?php
    include('connect.php');
    if(isset($_REQUEST['Register'])) {
        $errors = array(
            'email'    => '',
            'username' => '',
            //etc...
        );
    
        if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST[email])) { 
            $error['email'] = "The e-mail you entered was not in the proper format!"; 
        }
    }
    ?>
    

    and then in your HTML:

    <tr>
      <td>Email id :</td>
      <td>
        <input type="text" name="email" value="">
        <?php echo $error['email']; ?>
      </td>
    </tr>
    

    Furthermore don’t user eregi, it is deprecatad. Use preg_match instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am designing a simple registration form in ASP.net MVC 1.0 I want to
I'm designing a registration form in PHP using html. The form collects personal info
I'm designing an application that has an activity for registration process, this activity launches
I'm designing a registration form for a website, and was originally going to put
When designing an internation registration form how should I be asking for a user's
I have registration form and I am using Django-registration. Now, I need to add
Designing code to handle transfers of objects called contractBundles. Have this in the models.py
I'm designing a new web application and I'm aware that the process of registration
So I am designing a registration page and checking the username is alphanumeric. else
When designing both the domain-model and class-diagrams I am having some trouble understanding what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.