Registration Form validation With Javascripts

<html>
 <body>
 <script>
 function validate()
 {
 var name = document.getElementById("name").value;
 var email = document.getElementById("email").value;
 var phone = document.getElementById("phone").value;
 
 var error_name_id = document.getElementById("error_name");
 var error_email_id = document.getElementById("error_email");
 var error_phone_id = document.getElementById("error_phone");
 var error_msg = document.getElementById("error_msg");
 var success_msg = document.getElementById("success_msg");
 
 error_name_id.innerHTML ="";
 error_email_id.innerHTML ="";
 error_phone_id.innerHTML ="";
 
 if(name == null || name == "" || name == " ")
 {
    error_name_id.innerHTML ="Name is Empty";
    return false;
  }
  else if(email == null || email == "" || email == " ")
  { 
     error_email_id.innerHTML ="Email is Empty";
     return false; 
   }
   else if(phone == null || phone == "" || phone == " ") 
   { 
      error_phone_id.innerHTML ="Phone is Empty";
      return false; 
   }
   else
   { 
       // Now all is fine, Form can be submitted.
       return true; 
   }
} 
</script> 

<!-------FORM STARTED ----------------->

<form name="frm_register" name="" id="" action="" method="POST" onsubmit="return validate();"> 
<h3>Registration Form</h3>
Name: <input type="text" name="name" id="name" > 
<span id="error_name"></span>
<br/> 
<br/> 
Email: <input type="email" name="email" id="email"> 
<span id="error_email"></span> 
<br/> 
<br/> 
Phone: <input type="text" name="phone" id="phone"> 
<span id="error_phone"></span> 
<br/> 
<br/> 
<input type="submit" name="register" id="register" value="register"> <br/> 
<span id="error_msg" style="color:red"></span> 
<span id="success_msg" style="color:green;"></span> 
</form> 

<!-----------FORM ENDS --------------------->

</body> 
</html>

How to search data from table in php

———both HTML and php code in s1.php file—————-

<form method=”post” action=”s1.php?go” id=”searchform”>
<input type=”text” name=”name”>
<input type=”submit” name=”submit” value=”Search”>
</form>

 

<?php
if (isset($_POST[‘submit’]))
{
//connect to the database
$db = mysql_connect(“localhost”, “root”, “”) or die(‘I cannot connect to the database because: ‘ . mysql_error());
//-select the database to use
$mydb = mysql_select_db(“database_name”);if (isset($_GET[‘go’]))
{if (preg_match(“/[A-Z | a-z]+/”, $_POST[‘name’]))
{
$name = $_POST[‘name’];//-query the database table
$sql = “SELECT user_fname, user_lname FROM user WHERE user_fname LIKE ‘%” . $name . “%’ OR user_lname LIKE ‘%” . $name . “%'”;
//-run the query against the mysql query function
$result = mysql_query($sql);
//-create while loop and loop through result set
while ($row = mysql_fetch_array($result))
{
$FirstName = $row[‘user_fname’];
$LastName = $row[‘user_lname’];
echo $FirstName.$LastName;
}
}

}
}
?>