Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Opening a .html with window.location

I’m writing a simple login page in Ajax + Jquery
I have an error when I click on the button. And I don’t understand why.

Uncaught SyntaxError: Unexpected end of input

At this line
echo '<input type="button" value="connexion" OnClick="window.location.assign("http://localhost/loginmap/members/success.html")>';

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

There is my code

<?php 
session_start();
//si le user a un session de ouverte
    /*if(isset($_SESSION['connecté'])){
        header('Location : success.html');
        die();
    }*/
    if (isset($_POST['login'])) {
        $connection = new mysqli('localhost','root','','monumap');

        $email = $connection->real_escape_string($_POST['emailPHP']); 
        $password = $connection->real_escape_string($_POST['passwordPHP']); 

        $data = $connection->query("SELECT id FROM users WHERE email = '$email' AND password = '$password'"); 
        if($data->num_rows >= 0) {//tout et ok -> connexion
            $_SESSION['connecté'] = '1';
            //$_SESSION['email'] = $email;
            header('Location:'.$_SESSION['redirectURL']);
            exit('<font color = "green">Connexion reussi...</font>');
        }else{
            exit('<font color = "red">Le Mot de passe / Email est inconnue </font>');
        }
    
        //exit($email . " = " . $password);
    } 
?> 


<html> 
    <head> 
        <title>Monumap Connexion</title> 
    </head> 
    <body> 
        <form method="post" action="login.php">
            <input type="text" id="email" placeholder="Email..."><br> 
            <input type="password" id="password" placeholder="Mot de passe..."><br> 
            <input type="submit" value="Log In" id="login"> 
        </form> 
    
        <p id = "reponse"></p>

        <div class="Bouton">
            <?php if($_SESSION['connecté']==1){
                
                echo '<input type="button" value="connexion" OnClick="window.location.assign("http://localhost/loginmap/members/success.html")>';
            }
            ?>
        </div>

        <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
        <script type="text/javascript"> 
            $(document).ready(function () {
                $("#login").on('click', function () { 
                    var email = $("#email").val(); 
                    var password = $("#password").val(); 

                    if (email == "" || password == "") 
                        alert('vos inputs sont vides'); 
                    
                    else { 
                        $.ajax(
                            {
                                url: 'login.php',
                                method: 'POST', 
                                data: { 
                                    login: 1, 
                                    emailPHP: email, 
                                    passwordPHP: password 
                                },
                                success: function (reponse) {
                                    $("#reponse").html(reponse);
                                },
                                    dataType: 'text'
                            }
                        );
                    }
                });
            });
        </script>
    </body>
</html>

>Solution :

echo '<input type="button" value="connexion" onclick="window.location.assign('."'http://localhost/loginmap/members/success.html'".');")/>';

It’s cause you wrote quote character.

You can use this way as well.

echo '<input type="button" value="connexion" onclick="func()"/>';
?>

<script>
    function func(){
        window.location.assign("http://localhost/loginmap/members/success.html");
    }
</script>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading