插入数据后的消息

时间:2018-06-02 12:53:59

标签: php sql mysqli

当提交表单并在mysql中插入记录时,如何在页面顶部显示一条消息是我的action.php页面。

<?php $email =$_POST["email"];
include "includes/db_config.php";

$sql = "INSERT INTO subscribers(email)
VALUES('$email')";

if (mysqli_query($conn, $sql)) {
  header('location:index.php?subscribe=yes');

} else {
    echo "Failed" .  $sql . "<br>" . mysqli_error($conn);
}


?>

然后在index.php

<?php
    if ($_GET['subscribe'] =='yes'){
    echo 'You succesully subscribe to our exclusive promos';
    }
    ?>

1 个答案:

答案 0 :(得分:0)

您可以使用第index.php页中的JavaScript提醒框来实现此目的。

<?php
    if ($_GET['subscribe'] =='yes'){
       echo '<script language="javascript">';
       echo 'alert("Form has been submitted")';
       echo '</script>';
    }
?>

希望它有所帮助。