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.