Simple submit html form in database


Create html validation  form. the file name is the submitform.php

 

<html>
<head>
<script>
function validateForm()
{
var x=document.forms[“myForm”][“email”].value;
var atpos=x.indexOf(“@”);
var dotpos=x.lastIndexOf(“.”);
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
{
alert(“valid e-mail address”);
return false;
}
}

</script>

<body>

<table border=”1″ style=”border-color:#666666; background-color:#999999″ align=”center” width=”230px;”>
<tr>
<td>   Employees Data submit  in database </td>
</tr>
<tr>
<td>
<table>
<form action=”testephp.php” method=”post” name=”myForm” onsubmit=”return validateForm();”>
<tr>
<td> Fname</td><td><input type=”text” name=”fname”></td>
</tr>
<tr>
<td>Lname</td><td><input type=”text” name=”lname”></td>
</tr>
<tr>
<td>Id</td><td><input type=”text” name=”id”></td>
</tr>
<tr>
<td>Email</td><td><input type=”text” name=”email”></td></tr>
<tr>
<td>Pho No.</td><td><input type=”text” name=”pho”>
</td></tr>
<tr>
<td><label for=”file4″>File </label></td>
<td><input name=”file[]” type=”file” /></td>
</tr>

<tr><td></td>
<td align=”right”><input type=”submit” name=”submit” value=”submit”></td>
</tr>
</form>
</table>
</td>
</tr>
</table>

</body>
</head>
</html>

Create code for submit form in database. the file name is (tested.php)

<html>
<body>
<?php
mysql_connect(“localhost”,”root”,””) or die (mysql_error());
mysql_select_db(“db_ratnesh”) or die (mysql_error());

/* mysql_query(“create table insertform(id int, fname varchar (25), lname varchar (20), email varchar (50), pho int)”) or die (mysql_error());
echo “create table completed”;*/

if(isset($_POST[‘submit’]))

{
$fname=$_POST[‘fname’];
$lname=$_POST[‘lname’];
$id=$_POST[‘id’];
$email=$_POST[’email’];
$pho=$_POST[‘pho’];

$query=”INSERT INTO insertform VALUES (‘$fname’,’$lname’,’$id’,’$email’,’$pho’)”;
$result = mysql_query($query);

echo ” submit data successful in database”;

}

?>
<a href=”submitform.php”> go to input form</a>
</body>
</html>

 

Leave a comment