Thursday, 2 June 2016

html form with insert data in php

<html>
<head>
<link rel="stylesheet" href="int.css" />
<style>
.error {color: #FF0000;}
</style>
</head>
<body>
<?php
$i_namea = $f_namea = $emaila = $contacta= $r_filea = "";
$i_name = $f_name = $email = $contact= $r_file =  "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
   if (empty($_POST["i_name"])) {
     $i_namea = "Intervier name is required";
   } else {
     $i_name = test_input($_POST["i_name"]);
   }
 
   if (empty($_POST["f_name"])) {
     $f_namea = "father name is required";
   } else {
     $f_name = test_input($_POST["f_name"]);
   }
   
   if (empty($_POST["email"])) {
     $emaila = "email id is required";
   } else {
     $email = test_input($_POST["email"]);
   }
    if (empty($_POST["contact"])) {
     $contacta = "contact is required";
   } else {
     $contact = test_input($_POST["contact"]);
   }

   }
function test_input($data) {
   $data = trim($data);
   $data = stripslashes($data);
   $data = htmlspecialchars($data);
   return $data;
}
?>
<div id="mainform">
<!-- Required Div Starts Here -->
<form id="form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" enctype="multipart/form-data">
<h3>Intervier Form</h3>
<p id="returnmessage"></p>
<label>Name: <span>*</span></label>
<input type="text" name="i_name" placeholder="Name"/>
 <span class="error"><?php echo $i_namea; ?></span></br>
<label>Father Name: <span>*</span></label>
<input type="text" name="f_name" placeholder="father Name"/>
 <span class="error"><?php echo $f_namea; ?></span></br>
<label>Email: <span>*</span></label>
<input type="text" name="email" placeholder="Email"/>
<span class="error"><?php echo $emaila; ?></span></br>
<label>Contact No: <span>*</span></label>
<input type="text" name="contact" placeholder="10 digit Mobile no."/>
 <span class="error"><?php echo $contacta; ?></span></br>
<label>Resume: <span>*</span></label>
<input type="file" name="r_file">
<input type="hidden" name='id' value="<?php echo $_GET['id']; ?>" >
<input type="submit" name="submit" value="submit"/>
<a href="profile.php"><input type="button" name="" value="back"></a>
</form>
</div>
</body>
</html>
<?php include 'db.php' ?>
<?php
 if(isset($_POST['submit']))
 {
$i_name=$_POST['i_name'];
$f_name =$_POST['f_name'];
$email =$_POST['email'];
$contact =$_POST['contact'];
$info = pathinfo($_FILES['r_file']['name']);
$ext = $info['extension'];
$newname =  uniqid().".".$ext;
$target = 'name/'.$newname;
 move_uploaded_file( $_FILES['r_file']['tmp_name'], $target);
$sql="INSERT INTO inter_detail (i_name ,f_name, email, contact, r_file) VALUES ('$i_name', '$f_name', '$email','$contact','$newname')";
mysql_query($sql) or die(mysql_error());
}
?>

No comments:

Post a Comment