$(document).ready(function() {
$("submit").click(function(event) {
event.preventDefault();
});
});
function norefresh() {
return false;
}
<form method="post" action="<?php echo htmlspecialchars($_SERVER[" PHP_SELF "]);?>">
<div class="form-group">
<div class="row">
<div class="col-xs-6 col-md-6 form-group">
<label for="lname1">NAME OF THE LANDLORD</label>
<input type="text" class="form-control" id="lname" name="lname"></div>
<div class="col-xs-6 col-md-6 form-group">
<label for="lpan1">PAN OF LANDLORD</label>
<input type="text" class="form-control" id="lpan" name="lpan">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-6 col-md-6 form-group">
<label for="ladd1">ADDRESS OF LANDLORD</label>
<input type="text" class="form-control" id="ladd" name="ladd">
</div>
<div class="col-xs-6 col-md-6 form-group">
<label for="lacc1">ACCOMODATION ADDRESS</label>
<input type="text" class="form-control" id="lacc" name="lacc">
</div>
</div>
</div>
<input type="submit" class="btn btn-primary pull-right" name="submit" value="Add New" onClick="getintotab();resetform();return false;" />
<br> <br>
</form>
</div>
<?php
if(isset($_POST['submit'])){
$sql1 = $db->query("INSERT INTO Landlord(name, landlord_pan, landlord_address, acc_address) VALUES ('".$_POST["lname"]."','".$_POST["lpan"]."','".$_POST["ladd"]."','".$_POST["lacc"]."')");
if($sql1 == TRUE){
echo "";
}
else{
echo "Error: " . $sql1 . "<br>" . mysqli_error($db);
}
}
?>
The php script on clicking the submit button sends the form data to a mysql database and the getintotab()
function stores the form value on the same page in a table resetform()
resets the form
but on clicking the submit button the page gets reloaded.
I have already tried the following:
norefresh()
preventdefault()
- making the input type as button instead of submit
Still no luck