Hello, I try to insert values into my database (in phpmyadmin) hosted by a server (gandi) but this error appear and I don't know how to resolve it My error :
jquery.min.js:4 POST
http://95.... 500 (Internal Server Error)
send @ jquery.min.js:4
ajax @ jquery.min.js:4
(anonymous) @ (index):65
dispatch @ jquery.min.js:3
q.handle @ jquery.min.js:3
triggerMouseEvent @ ionic.bundle.js:2953
tapClick @ ionic.bundle.js:2942
tapMouseUp @ ionic.bundle.js:3018
My code :
app.controller('ajoutUtilisateurCtrl', function($scope)
{
$('#submit').click(function(){
var nom = $scope.nom;
var prenom = $scope.prenom;
var email = $scope.email;
var advertisement = $('#nom').val() + $('#prenom').val() + $('#email').val();
var datastring = {nom: nom, prenom: prenom, email: email};
if(advertisement=='')
{
$('#response').html('Veuillez saisir les données');
}
else{
$.ajax({
type: "POST",
url: "http://95.../ajoutUtilisateur.php",
data: datastring,
cache: false,
success: function(result){
$('#response').html(result);
var advertisement = $('#nom').val("") + $('#prenom').val("") + $('#email').val("");
}
});
return false;
}
})
});
ajoutUtilisateur.php
<?php
include_once('config.php');
$nom = $_POST['nom'];
$prenom = $_POST['prenom'];
$email = $_POST['email'];
$sql = "INSERT INTO utilisateur(nom, prenom, email) VALUES('$nom', '$prenom', '$email')";
if($connexion->query($sql) === TRUE){
echo 'Utilisateur ajouté';
}
else
{
echo 'Erreur ajout utilisateur';
}
?>
config.php
<?php
define('DB_HOST', 'localhost');
define('DB_NAME', 'db');
define('DB_USERNAME', 'user');
define('DB_PASSWORD', '');
$connexion = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME) or die("Could not connect to database");
if(mysqli_connect_errno()){
echo('Connexion non établie'.mysqli_connect_error());
exit();
}
?>
How can I resolve this problem ?