-1

for my internship in a school i created an ajax script that allows you to call a php page that will change data of a student in MySQL table. My problem is that all my program works with Chrome but not with Firefox.

Js:

 
        <script>
            function setBDD() {
                if (confirm("Êtes vous sur de vouloir changer ces informations ?") === true){ //pop up de confirmation
                    //les valeurs des input sont récupérée via leurs id.
                    let id = document.getElementById("id").value;
                    let nom = document.getElementById("nom").value;
                    let prenom = document.getElementById("prenom").value;
                    let sexe = document.querySelector('input[name="sexe"]:checked').value;
                    let date = document.getElementById("date").value;
                    let classe = document.getElementById("classe").value;
                    let site = document.getElementById("site").value;
                    let login = document.getElementById("login").value;
                    let password = document.getElementById("password").value;
                    let email = document.getElementById("email").value;
 
                    $.ajax({
                        type: "POST",
                        url: "modifier-a.php",
                        data: {
                            id: id,
                            nom: nom,
                            prenom: prenom,
                            sexe: sexe,
                            date: date,
                            classe: classe,
                            site: site,
                            login: login,
                            password: password,
                            email: email
                        },
                        success: function(response) {
                            console.log(response);
                        }
                    });
                }else{
                    alert('Annulation de la modification !');
                }
            }
        </script>

php :

 
<?php
include "include-php/connexion.php";
// Récupération des données envoyées par Ajax
if (isset($_POST['id']) && isset($_POST['nom']) && isset($_POST['prenom']) && isset($_POST['sexe']) && isset($_POST['date']) && isset($_POST['classe']) && isset($_POST['site']) && isset($_POST['login']) && isset($_POST['password']) && isset($_POST['email']) ) {
    $id = $_POST['id'];
    $nom = $_POST['nom'];
    $prenom = $_POST['prenom'];
    $sexe = $_POST['sexe'];
    $date = $_POST['date'];
    $classe = $_POST['classe']; 
    $site = $_POST['site'];
    $login = $_POST['login'];
    $password = $_POST['password'];
    $email = $_POST['email'];
 
    // Exécution de la mise à jour SQL
    $query = "UPDATE anciens SET NOM = '$nom', PRENOM = '$prenom', SEXE = '$sexe', DATE = '$date', CLASSE = '$classe', SITE = '$site', LOGIN = '$login', PASSWORD = '$password', EMAIL = '$email' WHERE ID = '$id'";
    
    $statement = $pdo->prepare($query);
    
    $statement->execute();
    
    if ($statement->rowCount() > 0) {
        echo "Mise à jour réussie";
    } else {
        echo "Aucune mise à jour effectuée";
    }
 
    // Fermeture de la connexion à la base de données
    $pdo = null;
}
?>

I also tried on the brave browser and it worked. I think it's a problem with firefox who can't understand my JS.

  • 1
    Any errors/warnings in your Firefox DevConsole (F12)? – brombeer Jun 21 '23 at 09:13
  • Where does `setBDD` get called? Did you debug into the function yet to verify at which point it starts to go wrong? – CBroe Jun 21 '23 at 09:14
  • 1
    **Warning!** You're open to [SQL injection attacks](https://owasp.org/www-community/attacks/SQL_Injection)! Read [how to prevent SQL injection in PHP](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) by using prepared statements with bound parameters instead of injecting variables directly into your queries. It's not just about security. If your data contains, for example, a single quote `'`, your query will break. – M. Eriksson Jun 21 '23 at 09:15
  • 1
    _Side note:_ Never store passwords in plain text! You should only store password hashes generated using [password_hash()](https://www.php.net/manual/en/function.password-hash.php) and to verify a password against a hash, use [password_verify()](https://www.php.net/manual/en/function.password-verify.php). – M. Eriksson Jun 21 '23 at 09:15
  • the function is called with this button which is in the same page as the script. And the firefox console tells me that there is no problem other than the lack of favicon – Noah Grasland Jun 21 '23 at 09:18
  • Check the "Network" tab in the DevConsole. Is the request sent? Does it get a response? Is the (correct) response printed to console (via `console.log(response)`)? What actually happens when you click the button? – brombeer Jun 21 '23 at 09:22
  • Yes I know that the passwords are stored in clear but it is the administration of the group which the school belongs that attributes the passwords and the emails. So to counter this problem that I created a session with php and is store the passwords for the admin in a new mysql table in sh256 – Noah Grasland Jun 21 '23 at 09:26
  • @broomer i found the line NS_BINDING_ABORTED – Noah Grasland Jun 21 '23 at 10:24
  • It's brombeer. If all your button does is call the Javascript I'd change `type="submit"` to `type="button"` – brombeer Jun 21 '23 at 10:47
  • @broobeer thank you very much it worked i just add location.reload(); to refresh my page – Noah Grasland Jun 21 '23 at 11:59

1 Answers1

0

I saw online that the error code NS_BINDING_ABORT on firefox meant that the request was stopped before reaching the desired page by changing my input type from submit to button (thanks to brombeer) i avoid refreshing the page before the end of the request and to show the changement i add location.load() for refrech the data. (sorry for bad english i'm french).