2016-12-15 100 views
1

朋友你好我在這段代碼有問題, 當我刷新網頁,然後數據自動插入到數據的基礎上,我那麼做數據未連連插入數據庫時​​,頁面加載。 這是我的代碼 -如何停止的數據重新輸入到數據庫時,頁面刷新

<?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> 
+0

[如何阻止可能的數據副本自動寫入插入數據庫在PHP](http://stackoverflow.com/questions/41176485/how-to-stop-data-automatically-insert-into-database-in-php) – e4c5

回答

0

,以避免數據插入時,頁面刷新,然後使用代碼AJEX或 只需 你如果()

if($result) 
{ 
echo 'SuccessFully saved data'; 
echo '<script>window.location.href="CURRENTPAGE.php"</script>'; 
} 
相關問題