Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在页面刷新时停止将数据重新输入数据库_Php_Html_Mysql_Css - Fatal编程技术网

Php 如何在页面刷新时停止将数据重新输入数据库

Php 如何在页面刷新时停止将数据重新输入数据库,php,html,mysql,css,Php,Html,Mysql,Css,朋友们好,我的代码有问题, 当我刷新网页时,数据会自动插入数据库,当页面加载时,我所做的数据不会一次又一次地插入数据库。 这是我的密码-- 为避免页面刷新时插入数据,请使用Ajex代码 或 只需写下你的if() if($result) { echo“已成功保存数据”; echo'window.location.href=“CURRENTPAGE.php”; } 为避免页面刷新时插入数据,请使用Ajex代码 或 只需写下你的if() if($result) { echo“已成功保存数据”; ech

朋友们好,我的代码有问题, 当我刷新网页时,数据会自动插入数据库,当页面加载时,我所做的数据不会一次又一次地插入数据库。 这是我的密码--


为避免页面刷新时插入数据,请使用Ajex代码
或
只需写下你的if()

if($result)
{
echo“已成功保存数据”;
echo'window.location.href=“CURRENTPAGE.php”;
}

为避免页面刷新时插入数据,请使用Ajex代码 或 只需写下你的if()

if($result)
{
echo“已成功保存数据”;
echo'window.location.href=“CURRENTPAGE.php”;
}
<?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>
if($result)
{
echo 'SuccessFully saved data';
echo '<script>window.location.href="CURRENTPAGE.php"</script>';
}