如何停止的数据重新输入到数据库时,页面刷新
问题描述:
朋友你好我在这段代码有问题, 当我刷新网页,然后数据自动插入到数据的基础上,我那么做数据未连连插入数据库时,页面加载。 这是我的代码 -如何停止的数据重新输入到数据库时,页面刷新
<?php
require './database/databaseConnection.php';
if(isset($_POST['save_button']))
{
if(($_POST['fname']&&($_POST['lname'])))
{
$first_name=$_POST['fname'];
$last_name=$_POST['lname'];
$qry="INSERT INTO user_master(first_name,last_name) values('$first_name','$last_name')";
$result= mysql_query($qry)or die(mysql_error());
if($result){
echo 'SuccessFully saved data';
}
else{
echo 'Data Not Inserted!';
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link rel="stylesheet" href="bootStrap/css/bootstrap.min.css">
<link rel="stylesheet" href="bootStrap/css/bootstrap.css">
</head>
<body>
<div class="container jumbotron ">
<form action="" method="post">
<table class="table-responsive">
<div class="form-group form-inline">
<tbody>
<tr>
<td> <label for="fname" class="label-info">First Name</label></td>
<td><input class="form-control" type="text" name="fname"></td>
<td><label for="lname" class="label-info">Last Name</label></td>
<td><input class="form-control" type="text" name="lname"></td>
</tr>
</tbody>
</div>
</table>
<button type="submit" name="save_button" class="btn-success" >Save Data</button>
</form>
</div>
</body>
</html>
答
,以避免数据插入时,页面刷新,然后使用代码AJEX或 只需 你如果()
if($result)
{
echo 'SuccessFully saved data';
echo '<script>window.location.href="CURRENTPAGE.php"</script>';
}
[如何阻止可能的数据副本自动写入插入数据库在PHP](http://stackoverflow.com/questions/41176485/how-to-stop-data-automatically-insert-into-database-in-php) – e4c5