如何将我的 sweetalert 链接到 php echo 标签中的另一个页面?

发布于 2025-01-14 02:59:26 字数 923 浏览 0 评论 0原文

我正在使用 Sweet Alert 向用户发送一条警告消息,向他们显示信息插入在 PHP echo 中无效。我想要“好的”按钮链接到所需页面,但它无法工作。我的开发人员控制台显示 login.php:29 Uncaught TypeError: Cannot read properties of undefined (reading 'then') 错误,但我不知道如何才能完成这项工作。我花了几个小时四处寻找,但就是没有。任何向我伸出援助之手的人都会受到真正的感激。谢谢。

以下是我的代码:

if (isset($_POST['login'])) {
    $email = $_POST['email'];
    $user_password = $_POST['user_password'];


    $sql = "SELECT * FROM users WHERE user_phone = '$email' OR username = '$email' ";
    $query = $conn->query($sql);
if ($query->num_rows < 1) {
    echo '<script> swal({
            title: "Wrong information",
            text: "Sorry, your login information is not in our system. Please check your username/email correctly.",
            confirmButtonText: "Okay"}).then(function() {
                window.location = "../login/index.php";
            }); 
            </script>';

}

I'm using sweet alert to send the user a warning message that show to them that the information insert is not valid in PHP echo. I want the "okay" button link to the desire page but it just could not work. my developer console shows the error of login.php:29 Uncaught TypeError: Cannot read properties of undefined (reading 'then') but I have no idea how can I make this work. I spent hours searching here and there but it just don't. Anyone who lend me a helping hand will be truly appreciated. Thanks.

Below are my codes:

if (isset($_POST['login'])) {
    $email = $_POST['email'];
    $user_password = $_POST['user_password'];


    $sql = "SELECT * FROM users WHERE user_phone = '$email' OR username = '$email' ";
    $query = $conn->query($sql);
if ($query->num_rows < 1) {
    echo '<script> swal({
            title: "Wrong information",
            text: "Sorry, your login information is not in our system. Please check your username/email correctly.",
            confirmButtonText: "Okay"}).then(function() {
                window.location = "../login/index.php";
            }); 
            </script>';

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文