Playlist
Powered by Blogger.

Insert Data with jQuery Validation in PHP

<!DOCTYPE html> <html> <head> <title></title> <link href="clg_css.css" type="text/cs...

Search This Blog

Popular Posts

Insert Data with jQuery Validation in PHP

<!DOCTYPE html>
<html>
<head>
<title></title>

<link href="clg_css.css" type="text/css" rel="stylesheet" />

  <link href="runnable.css" rel="stylesheet" />

<script src="//code.jquery.com/jquery-1.9.1.js"></script>
   <script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
 

  <!-- jQuery Form Validation code -->


 <script>

//display image after select
function readURL(input) {

    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function (e) {
            $('#blah').attr('src', e.target.result);
        }

        reader.readAsDataURL(input.files[0]);
    }
}

$("#img").change(function(){
    readURL(this);
});
// end image code

 // $(function() {

$(document).ready(function(){

    $("#register-form").validate({
        rules: {
            snm: "required",
            fnm: "required",
            lnm: "required",
            g: "required",
            bdt: "required",
            Mobile:{
            required:true,
            maxlength:12
            },
            email:{
            email:true,
            required:true
            },
            p_add:"required",
           
            l_add:"required",
           
            seatno:{
            required:true,
            maxlength:5
            },

            pass_yr:{
            required:true,
            maxlength:4
            },
            tmarks:{
            required:true,
            maxlength:3
            },
            omarks:{
            required:true,
            maxlength:3
            },
            img:"required",

            created_on:"required"

        },
       
        // Specify the validation error messages
        messages: {
            snm: "Please enter your surname",
            fnm: "Please enter your firstname",
            lnm: "Please enter your lastname",
            g: "Please select gender",
            bdt:"Please enter your birth date",
            Mobile: "Please enter your valid mobile no",
            email: "Please enter your valid email",
            p_add: "Please enter your permenant address",
            l_add: "Please enter your local address",
            seatno: "Please enter your 12th exam seatno ",
            pass_yr: "Please enter your 12th exam passing year",
            tmarks: "Please enter your 12th total marks",
            omarks: "Please enter your 12th obtain marks",
            img:"select photo",
            created_on:"enter created on date"



        },
       
        submitHandler: function(form) {
            form.submit();
        }
    });
  });
</script>
</head>
<body>

<?php include"header.php"; ?>
<h3 align="right"><a href="view.php">VIEW</a></h3>

<center>



<form action="" method="POST" enctype="multipart/form-data" id="register-form" novalidate="novalidate">
<table class="table">
<h4 style="font-size: 28px; color: blue;">fill up form</h4>

<tr>
<td class="lbl">Sname:</td>
<td><input type="text" name="snm" id="snm" class="txt" /></td></tr>

<tr>
<td class="lbl">fname:</td>
<td><input type="text" name="fnm" id="fnm" class="txt" /></td></tr>

<tr>
<td class="lbl">lname:</td>
<td><input type="text" name="lnm" id="lnm" class="txt" /></td></tr>


<tr>
<td class="lbl">gender:</td>
<td>Male<input type="radio" name="g" id="ml"/>Female<input type="radio" name="g" id="fml"  /></td></tr>

<tr>
<td class="lbl">birh date:</td>
<td><input type="date" name="bdt" id="bdt" class="txt" /></td></tr>

<tr>
<td class="lbl">Mobile:</td>
<td><input type="text" name="Mobile" id="Mobile" class="txt" /></td></tr>

<tr>
<td class="lbl">E-mail:</td>
<td><input type="text" name="email" id="email" class="txt" /></td></tr>

<tr>
<td class="lbl">per add:</td>
<td><textarea name="p_add" id="p_add" rows="2" columns="20" class="txt" /></textarea></td></tr>

<tr>
<td class="lbl">local add:</td>
<td><textarea name="l_add" id="l_add" rows="2" columns="20" class="txt" /></textarea></td></tr>

<tr>
<td class="lbl">seatno:</td>
<td><input type="text" name="seatno" id="seatno" class="txt" /></td></tr>

<tr>
<td class="lbl">passingyear:</td>
<td><input type="text" name="pass_yr" id="pass_yr" class="txt" /></td></tr>

<tr>
<td class="lbl">totalmarks:</td>
<td><input type="text" name="tmarks" id="tmarks" class="txt" /></td></tr>

<tr>
<td class="lbl">obtainmarks:</td>
<td><input type="text" name="omarks" id="omarks" class="txt" /></td></tr>

        <tr>
        <td class="lbl">Hobby:</td>
        <td><input type="checkbox" name="hobby[]" value="cricket"  />Cricket<br>
            <input type="checkbox" name="hobby[]" value="Reading"  />Reading<br>
            <input type="checkbox" name="hobby[]" value="swimming"  />Swimming<br></td></tr>

<tr>
<td class="lbl">image:</td>
<td><input type="file" name="img" id="img" class="txt" /><img id="blah" height="auto" width="125px" src="default.gif" /></td></tr>

        <tr>
        <td class="lbl">gellary:</td>
        <td><input type="file" name="gallery[]" multiple="" id="img" class="txt" /></td></tr>


<tr>
<td class="lbl">Createdon:</td>
<td><input type="date" name="created_on" id="created_on" class="txt" /></td></tr>

<tr><td align="center" colspan="2">
<input type="submit" name="submit" value="submit" class="btn" /></td></tr>
</table>
</form>

</center>





<?php


if(isset($_POST['submit']))
{
 include"connect.php";

$snm=$_POST['snm'];
$fnm=$_POST['fnm'];
$lnm=$_POST['lnm'];
$gender=$_POST['g'];
$bdt=$_POST['bdt'];
$mo=$_POST['Mobile'];
$eml=$_POST['email'];
$p_add=$_POST['p_add'];
$l_add=$_POST['l_add'];
$seatno=$_POST['seatno'];
$pass_yr=$_POST['pass_yr'];
$tmarks=$_POST['tmarks'];
$omarks=$_POST['omarks'];
$hobby=implode(",",$_POST['hobby']);

//image
$img = $_FILES['img']['name'];
$tmp = $_FILES['img']['tmp_name'];
$size = $_FILES['img']['size'];
$type = $_FILES['img']['type'];

 move_uploaded_file($tmp,'../college/image/'.$img);

        //gellary
 $image=array();
        foreach ($_FILES['gallery']['tmp_name'] as $key =>$tmp_name)
        {
            $gallary=$_FILES['gallery']['name'][$key];
            $gtmp=$_FILES['gallery']['tmp_name'][$key];
            if(move_uploaded_file($gtmp,"../college/gellary/".$gallary))
            {
                //echo "sucess";
            }
            array_push($image, $gallary);
        }
        $gallery=implode(",", $image);


$created_on=$_POST['created_on'];

echo $query="insert into student(sname,fname,lname,gender,birth_date,mobile,email,per_add,local_add,hsc_seatno,passing_year,total_marks,
            obtain_marks,hobby,image,gallery,created_on) values('$snm','$fnm','$lnm','$gender','$bdt','$mo','$eml','$p_add','$l_add','$seatno','$pass_yr','$tmarks','$omarks','$hobby','$img','$gallery','$created_on')";


mysql_query($query) or die (mysql_error());




echo "<script>alert('registration successfully')</script>";



}


?>




</body>
</html>
Publisher: Kishan Bhensadadiya - October 11, 2017

Excuses don't get results.

→ Life is one time offer. Use it well...
→ Hustle until your haters ask if you hiring.
→ Speak less than you know, have more than you show.

 
Publisher: Kishan Bhensadadiya - August 01, 2017
 

 

Our Leading Clients

Awesome people who trust us