Code:
<script type="text/javascript">
function validate(frm)
{
var x=document.forms["form2"]["fname1"].value;
if (x==null || x=="")
{
alert("First name must be filled out");
return false;
}
var y=document.forms["form2"]["lname1"].value;
if (y==null || y=="")
{
alert("last name must be filled out");
return false;
}
var w=document.forms["form2"]["std1"].value;
if(w == "")
{
alert("Please Enter Std-Code.");
return false;
}
if(isNaN(w))
{
alert("Please Enter Valid Std-Code.");
return false;
}
if(w.length < 3)
{
alert("Std-Code should be minimum 3 digits");
return false;
}
var p=document.forms["form2"]["phone1"].value;
if(p == "")
{
alert("Please Enter Phone Number.");
return false;
}
if(isNaN(p))
{
alert("Please Enter Valid Phone Number.");
return false;
}
if(p.length < 7)
{
alert("Contact Number should of minimum 7 digits");
return false;
}
var b=document.forms["form2"]["mobile1"].value;
if(b == "")
{
alert("Please Enter Mobile Number.");
return false;
}
if(b!=""){
if(isNaN(b))
{
alert("Please Enter Valid Mobile Number.");
document.form1.b.value='';
return false;
}
if(b.length < 10)
{
alert("Mobile Number should be minimum 10 digits");
return false;
}
}
}
function add_feed()
{
var div1 = document.createElement('div');
// Get template data
div1.innerHTML = document.getElementById('newlinktpl').innerHTML;
// append to our form, so that template data
//become part of form
document.getElementById('newlink').appendChild(div1);
}
</script>
<?php
if(isset($_POST['submit1']))
{
$sql="INSERT INTO `jos_callbackentry` (`fname1`, `lname1`, `std1`, `phone1`, `mobile1`) VALUES ( '$_POST[fname1]', '$_POST[lname1]', '$_POST[std1]', '$_POST[phone1]', '$_POST[mobile1]')";
mysql_query($sql);
}
?>
<!--here we insert html code -->
<form method="post" action="" name="form2" id="form2" onsubmit="return validate(this)">
<table>
<tr>
<td valign=top>Submit Callback Entry</td>
<td valign=top>
<div id="newlink">
<div class="feed">
<!-- <input type="text" name="feedurl[]" value="http://feeds.feedburner.com/satya-weblog/scripting" size="50"> <br > -->
<table width="100%" border="0"align="center" cellpadding="0" cellspacing="0" class="offwhite">
<tr>
<td> <table width="100%" border="0" align="center" cellpadding="5" cellspacing="1" class="white">
<tr class="sidemenuebg">
<td width="12%" align="right" nowrap><font color="#FF0000">*</font>First Name</td>
<td width="39%"><input name="fname1" id="fname1" type="text" size="25" maxlength="100" ></td>
<td width="20%" align="right"><font color="#FF0000">*</font> Last Name</td>
<td width="31%"><input name="lname1" id="lname1" type="text" size="25" maxlength="100" ></td>
</tr>
<tr class="simplegraytable">
<td colspan="2" align="right" nowrap>Phone</td>
<td align="left"><input name="std1" id="std1"type="text" size="5" maxlength="5" >
<input name="phone1" id="phone1" type="text" size="20" maxlength="10" >
<br >
<span class="style5">STD Code - Number</span></td>
<td align="right"><font color="#FF0000">*</font>Mobile</td>
<td align="left"><input name="mobile1" id="mobile1" type="text" size="25" maxlength="10" onkeyup="checkNumber(this);"></td>
</tr>
</table> </td></tr></table>
</div>
</div>
</td>
</tr>
</table>
<p>
<br>
<input type="submit" name="submit1">
<input type="reset" name="reset1">
</p>
<p id="addnew">
<a href="javascript:add_feed()">Add New </a>
</p>
</form>
<!-- Template. This whole data will be added directly to working form above -->
<div id="newlinktpl" style="display:none">
<div class="feed">
<table width="100%" border="0"align="center" cellpadding="0" cellspacing="0" class="offwhite">
<tr>
<td> <table width="100%" border="0" align="center" cellpadding="5" cellspacing="1" class="white">
<tr class="sidemenuebg">
<td width="5%" align="right" nowrap class="simplegraytable">
</td>
<td width="12%" align="right" nowrap><font color="#FF0000">*</font>First Name</td>
<td width="39%"><input name="fname1" id="fname1" type="text" size="25" maxlength="100" ></td>
<td width="13%" align="right"><font color="#FF0000">*</font>Last Name</td>
<td width="31%"><input name="lname1" id="lname1" type="text" size="25" maxlength="100" ></td>
</tr>
<tr class="simplegraytable">
<td colspan="2" width="12%" align="right" nowrap>Phone</td>
<td align="left"><input name="std1" id="std1"type="text" size="5" maxlength="5" >
<input name="phone1" id="phone1" type="text" size="20" maxlength="10" >
<br >
<span class="style5">STD Code - Number</span></td>
<td align="right"><font color="#FF0000">*</font>Mobile</td>
<td align="left"><input name="mobile1" id="mobile1" type="text" size="25" maxlength="10" onkeyup="checkNumber(this);"></td>
</tr>
</table></td></tr></table>
</div>
</div>
when i fill information in filed without click "add new"
then information store in table
but when i click on "add new" suppose there in 2 form filed then the second last entry information is store in table and first form entry not store in table .
Plz........ guide me how i can store all information in table when i click on "add new" without redundancy of information.
Comment