I've been working on a way to push variables from my application to my database. It now succesfully makes a connection, but it doesn't push the variables into the database (It makes a new row, but the the variables are empty.)
I'll post my http.get
$scope.signupuser = function(info){
$scope.user = [];
$scope.user.email =
$scope.user.voornaam =
$scope.user.achternaam =
$scope.user.postcode =
$scope.user.woonplaats =
$scope.request = $http({
url: "www.test.com/example.php",
method: "POST",
params: {
voornaam: $scope.user.voornaam,
achternaam: $scope.user.achternaam,
email: $scope.user.email,
postcode: $scope.user.postcode,
woonplaats: $scope.user.woonplaats
},
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});
$scope.request.success(function(data, status, headers, config){
console.log("inserted Successfully")
})
My example.php
<?php
include '../dbconnect.php';
try {
json_decode(file_get_contents("php://input"));
print_r($_POST);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO
users (
email,
voornaam,
achternaam,
postcode,
woonplaats
) VALUES (
'$email',
'$voornaam',
'$achternaam',
'$postcode',
'$woonplaats'
)";
// use exec() because no results are returned
$conn->exec($sql);
echo "New record created successfully";
} catch(PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}
$conn = null;
?>
I suspect there is an error in how example.php handles the delivered variables, but I am not sure.
Thanks in advance! :)
EDIT:
Error message for clarification
Array ( [{"voornaam":"gfa","achternaam":"g","email":"JohnDoe@gmail.com","postcode":"8271AT","woonplaats":"fdsa"}] => )
Notice: Undefined index: email in /var/www/vhosts/text.com/httpdocs/example.phpon line 13
Notice: Undefined index: voornaam in /var/www/vhosts/text.com/httpdocs/example.php on line 14
Notice: Undefined index: achternaam in /var/www/vhosts/text.com/httpdocs/example.php on line 15
Notice: Undefined index: postcode in /var/www/vhosts/text.com/httpdocs/example.php on line 16
Notice: Undefined index: woonplaats in /var/www/vhosts/text.com/httpdocs/example.php on line 17
New record created successfully
SECOND EDIT:
Print_r($_POST)
Array ( [{"voornaam":"Jogn","achternaam":"Doe","email":"johndoe@gmail_com","postcode":"3252AR","woonplaats":"Zwolle"}] => )
print_r($_POST[0])
Notice: Undefined offset: 0 in /var/www/vhosts/test.com/httpdocs/example.php on line 9
print_r($_REQUEST)
Array ( [{"voornaam":"Jogn","achternaam":"Doe","email":"johndoe@gmail_com","postcode":"3252AR","woonplaats":"Zwolle"}] => )