Jump to content

how to link my sweetalert to another page in php echo tag?


sashavalentina

Recommended Posts

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>';
                         }

 

Link to comment
Share on other sites

Use php to set a variable containing the number of rows in the HTML. Then use JavaScript to get that variable, check it, and react accordingly. Don't mix the two like you've done - technically, it's kinda possible but as you're seeing now it's a complete pain.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.