简体   繁体   English

用户提交表单时如何显示消息

[英]How to display message when a user submits the form

Hi I have the following code. 嗨,我有以下代码。 I was just wondering how to add a message/popup to say "thanks for registering" if everything is successful. 我只是想知道如果一切成功,如何添加一条消息/弹出窗口说“感谢注册”。 Here is the code and btw i am new the php. 这是代码,顺便说一句,我是新的php。 Thanks for your help 谢谢你的帮助

<?php 
require("config.php");
if(!empty($_POST)) 
{ 
    // Ensure that the user fills out fields 
    if(empty($_POST['username'])) 
    { die("Please enter a username."); } 
    if(empty($_POST['password'])) 
    { die("Please enter a password."); } 
    if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) 
    { die("Invalid E-Mail Address"); } 

    // Check if the username is already taken
    $query = " 
        SELECT 
            1 
        FROM users 
        WHERE 
            username = :username 
    "; 
    $query_params = array( ':username' => $_POST['username'] ); 
    try { 
        $stmt = $db->prepare($query); 
        $result = $stmt->execute($query_params); 
    } 
    catch(PDOException $ex){ die("Failed to run query: " . $ex->getMessage()); } 
    $row = $stmt->fetch(); 
    if($row){ die("This username is already in use"); } 
    $query = " 
        SELECT 
            1 
        FROM users 
        WHERE 
            email = :email 
    "; 
    $query_params = array( 
        ':email' => $_POST['email'] 
    ); 
    try { 
        $stmt = $db->prepare($query); 
        $result = $stmt->execute($query_params); 
    } 
    catch(PDOException $ex){ die("Failed to run query: " . $ex->getMessage());} 
    $row = $stmt->fetch(); 
    if($row){ die("This email address is already registered"); } 

    // Add row to database 
    $query = " 
        INSERT INTO users ( 
            username, 
            password, 
            salt, 
            email 
        ) VALUES ( 
            :username, 
            :password, 
            :salt, 
            :email 
        ) 
    "; 


    // Security measures
    $salt = dechex(mt_rand(0, 2147483647)) . dechex(mt_rand(0, 2147483647)); 
    $password = hash('sha256', $_POST['password'] . $salt); 
    for($round = 0; $round < 65536; $round++){ $password = hash('sha256', $password . $salt); } 
    $query_params = array( 
        ':username' => $_POST['username'], 
        ':password' => $password, 
        ':salt' => $salt, 
        ':email' => $_POST['email'] 
    ); 
    try {  
        $stmt = $db->prepare($query); 
        $result = $stmt->execute($query_params); 
    } 
    catch(PDOException $ex){ die("Failed to run query: " . $ex->getMessage()); } 
    header("Location: index.php"); 

    die("Redirecting to index.php"); 


} 

?> ?>

Try this -- insert instead of the header( Location:index.php); 试试这个-插入而不是header( Location:index.php); and die() lines: die()行:

Following will display Thanks message for FIVE ( content=5) seconds before redirecting to index.php 在重定向到index.php之前,以下内容将显示感谢消息,持续content=5)content=5)

echo '<h1>Thanks for registering</h1>';
echo '<meta HTTP-EQUIV="REFRESH" content="5; url=index.php">';

Did you consider using jquery? 您是否考虑过使用jquery? You can use the "$("#id").submit(function(event)){} with one alert, it will give you a popup with a personalized message. 您可以通过一个警报使用“ $(”#id“)。submit(function(event)){},它会弹出带有个性化消息的弹出窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当用户使用Laravel提交联系表单时接收电子邮件 - Receive email message when user submits contact form using Laravel 如何创建表,当用户提交表单时在其中填充行 - How to create a table, in which rows are filled in when a user submits a form 用户提交表单时如何通过电子邮件发送联系表单 - how to send a contact form by email when user submits forms 当用户提交表单时如何在表格单元格中呈现任务 - How to render a task in a table cell when a user submits the form 用户提交表单时未显示日期 - Date not showing up when user submits form 当用户使用PHP提交消息时,如何在同一页面上添加错误或成功消息 - How to add a error or sucess message on the same page, when the user submits a message in PHP PHP如何在用户提交表单时更新文本 - PHP How to update text if a user submits a form 当多个提交不属于表单时如何处理 - How to handle several submits when they are not part of a form 当用户在我的网站上提交表单时,如何从getresponse.com发送邮件? - How to send a mail from getresponse.com when user submits a form in my website? 当用户提交表单时,如何提交到iframe并在主页上显示结果? - When the user submits a form how can it submit to an iframe and show a result on the main page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM