JavaScript/PHP:成功保存后的警报对话框

我是编程新手。目前,我开发了一个系统,注册部分。注册部分成功保存到数据库中。我想知道的是如何在注册成功后弹出一个带有一个按钮的警报对话框,例如“确定”并重定向到另一个页面,例如主页。现在我只回声“成功保存”


下面是我当前的代码


<?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);

}


?>


慕虎7371278
浏览 105回答 2
2回答

梵蒂冈之花

只需使用 php 标头并使用 javascript 来提醒消息。&nbsp; &nbsp; &nbsp; if(mysqli_query($conn,$sql_query))&nbsp; &nbsp; {&nbsp; &nbsp; echo "<script>alert('Successfuly Saved');</script>";&nbsp;header('Location: PATH TO BE REDIRECTED');&nbsp; &nbsp; }举个例子if(mysqli_query($conn,$sql_query))&nbsp; &nbsp; {&nbsp; &nbsp; echo "<script>alert('Successfuly Saved');</script>";&nbsp;header('Location: ../Insert/Index.php');&nbsp; &nbsp; }请注意 Location: 之间的空格是强制性的
打开App,查看更多内容
随时随地看视频慕课网APP