[英]JavaScript/PHP: Alert dialog after successfully saved
I new in programming. 我是编程新手。 Currently, I develop a system that registration part. 目前,我开发了一个注册部分的系统。 The registration part is successfully saved to the database. 注册部分已成功保存到数据库中。 What I want to know is how to popup an alert dialog with one button eg "Ok" after registration was successful and redirect to another page, such as home page. 我想知道的是如何在注册成功后用一个按钮弹出警告对话框,例如“确定”,并重定向到另一个页面,例如主页。 Now I only echo "successfully saved" 现在我只回应“成功保存”
Below is my current code 以下是我目前的代码
<?php
require "DbConnect.php";
$name = $_POST['name'];
$badgeid = $_POST['badgeid'];
$position = $_POST['position'];
$department = $_POST['department'];
$factory = $_POST['factory'];
$reviewer = $_POST['reviewer'];
$title = $_POST['title'];
$year = $_POST['year'];
$month = $_POST['month'];
$suggestionwill = $_POST['suggestionwill'];
$present = $_POST['present'];
$details = $_POST['details'];
$benefit = $_POST['benefit'];
$sql_query = "INSERT INTO topsuggest (name,badgeid,position,department,factory,
reviewer,title,year,month,suggestionwill,present,details,benefit) VALUES('$name','$badgeid','$position','$department','$factory','$reviewer','$title','$year','$month','$suggestionwill','$present','$details','$benefit')";
if(mysqli_query($conn,$sql_query))
{
echo "<p id='msg'></p>";
}
else
{
echo "Error!! Not Saved".mysqli_error($con);
}
?>
Just use php header and use javascript to alert a message . 只需使用php标头并使用javascript来提醒消息。
if(mysqli_query($conn,$sql_query))
{
echo "<script>alert('Successfuly Saved');</script>";
header('Location: PATH TO BE REDIRECTED');
}
For a example 举个例子
if(mysqli_query($conn,$sql_query))
{
echo "<script>alert('Successfuly Saved');</script>";
header('Location: ../Insert/Index.php');
}
Please note that space between Location: is compulsory 请注意,位置:之间的空间是强制性的
After inserting data you can simply redirect to your interested page with a success message like: 插入数据后,您只需使用以下成功消息重定向到您感兴趣的页面:
header("location:page_of_interest.php?msg=Record Inserted");
and on page_of_interest.php
you can simply check for msg and show if it is set like: 在page_of_interest.php
您只需检查msg并显示它是否设置为:
if(isset($_GET['msg'])){
echo $_GET['msg'];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.