代码之家  ›  专栏  ›  技术社区  ›  Chrissa

插入数据后的消息

  •  0
  • Chrissa  · 技术社区  · 6 年前

    提交表单并在下面的mysql中插入记录后,如何在页面顶部显示消息是my 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 回复  |  直到 6 年前
        1
  •  0
  •   Ratnadeep    6 年前

    您可以在页面中使用javascript警报框 index.php 为此目的。

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

    希望有帮助。