---
title: "How to create program to validation in php"  
description: "How to create program to validation in php"  
author: "zack mathews"  
published: 2016-09-07  
updated: 2016-09-07  
canonical: https://www.mindstick.com/forum/34172/how-to-create-program-to-validation-in-php  
category: "php"  
tags: ["php", "validation"]  
reading_time: 2 minutes  

---

# How to create program to validation in php

Hi guys\
I am [beginner](https://www.mindstick.com/forum/23159/need-beginner-project-ideas) in [php](https://www.mindstick.com/articles/12149/php-constant-and-php-variables) programming.Please [explain me](https://www.mindstick.com/forum/34220/can-anyone-explain-me-about-off-page-activity) [program code](https://www.mindstick.com/interview/33814/what-will-be-the-output-of-following-program-code) to [validation](https://www.mindstick.com/articles/12234/validation-using-data-annotation-using-entity-framework) in php.\
Thanks

## Replies

### Reply by Royce Roy

Hi you can create script validation.php like this

```
<?php
//connection is made with database
$con = mysqli_connect("localhost","username",”password”, 'database name');
//when the form is submmited it will insert the values entered by user
if(isset($_POST["submit"]))
{             $uname=$_POST["uname"];
            $pass=$_POST["pass"];
            $name=$_POST["name"];
            $dob=$_POST["year"]."-".$_POST["month"]."-".$_POST["day"];
            $phone=$_POST["phone"];
//It will insert the value in database which is enterd by the user.
$con->query("insert into user_login values('$uname','$pass','$name','$dob',$phone)");
 }
?>
//client side validation
<script>
function validate()
{
//If any of the fields is left empty or null,this function will validate the fields and alerts a message to returns false,to prevent the form being submitted
              var uname=document.forms["myForm"]["uname"].value;
             var uname=document.forms["myForm"]["pass"].value;
             var uname=document.forms["myForm"]["name"].value;
             var uname=document.forms["myForm"]["phone"].value;
   if(uname == null || uname == "" )
             {                         alert("Username must be filled.");
                         return false;
            }
   if (document.getElementById('year').value == 'Select')
           {                        alert("Please select Year");
                       return false;           }
  else if (document.getElementById('month').value == 'Select')
          {
                       alert("Please select Month");
                       return false;
          }
   else if (document.getElementById('day').value == 'Select')
         {                       alert("Please select Day");                       return false;
         }
}
</script>
```


---

Original Source: https://www.mindstick.com/forum/34172/how-to-create-program-to-validation-in-php

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
