PHP slaat niks op in data (submit.php)
Alles loop gewoon, zonder dat er geklaagd wordt in de console log, bovendien geef de console.log ook precies aan wat er naar de PHP getransmit moet worden. Alleen als ik de website refresht dan verdwijnt de gegeven weer. Het wordt dus niet opgeslagen. Waar ligt dit aan. Ik maak gebruik van de volgende gratis web hosting cp1.freehostingeu.com. Hier kan ik de php.ini niet aanpassen. Zou dat de oorzaak kunnen zijn? Weet niet of ik daar namelijk iets moet aanpassen zodat het in de data opgeslagen kan worden.
php file
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
/**
* @filesource : submit.php
* @author : Shabeeb <[email protected]>
* @abstract : simple submission php form
* @package sample file
* @copyright (c) 2014, Shabeeb
* shabeebk.com
*
* */
$post_date = file_get_contents("php://input");
$data = json_decode($post_date);
//saving to database
//save query
//now i am just printing the values
echo "Name : ".$data->name."\n";
echo "Email : ".$data->email."\n";
echo "Message : ".$data->message."\n";
//echo "Hello world";
?>
/**
* @filesource : submit.php
* @author : Shabeeb <[email protected]>
* @abstract : simple submission php form
* @package sample file
* @copyright (c) 2014, Shabeeb
* shabeebk.com
*
* */
$post_date = file_get_contents("php://input");
$data = json_decode($post_date);
//saving to database
//save query
//now i am just printing the values
echo "Name : ".$data->name."\n";
echo "Email : ".$data->email."\n";
echo "Message : ".$data->message."\n";
//echo "Hello world";
?>
Angular file
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
$scope.addComment = function(dataObject) {
if(dataObject) {
$http.post($scope.url, {"name": $scope.dataObject.name, "email": $scope.dataObject.country, "message": $scope.dataObject.comment}).
success(function(data, status) {
console.log(data);
$scope.status = status;
$scope.data = data;
$scope.result = data;
$scope.dataObject = {
name: "",
country: "",
comment: ""
};
})
$scope.comments.push(dataObject);
} else {
console.log("Form is not valid");
}
};
html file
<script type="text/ng-template" id="pages/forum.html">
<div ng-controller="Forum" class="forum-page">
<div class="col-lg-12">
<div id="comment-block">
<div id="comment-list" ng-repeat="comment in comments">
<div id="text-block">
<div class="comment-info name">{{comment.name}}</div>
<div class="comment-info" id="comment">{{comment.comment}}</div>
<div class="comment-info countries">{{comment.country}}</div>
</div>
</div>
<ng-form name="comment_box" id="comment-box">
<input type="text" class="comment-form" id="name" ng-model="dataObject.name" ng-minlength="2" ng-maxlength="20" ng-required="true" placeholder="Name">
<select class="comment-form" ng-model="dataObject.country" ng-options="x.country as x.country for x in options" ng-required="true">
<option value="">-- Choose Country --</option>
</select>
<textarea type="text" class="comment-form countries" ng-model="dataObject.comment" rows="6" cols="90" ng-minlength="1" ng-maxlength="300" ng-required="true" placeholder="Comment"></textarea>
<span class="comment-form" id="remain_amount_of_letters">{{300-dataObject.comment.length}} Left</span>
<button class="comment-form comment-button" ng-disabled="comment_box.$invalid" type="submit" ng-click="addComment(dataObject)">Place comment</button>
</ng-form>
</div>
</div>
</div>
</script>
if(dataObject) {
$http.post($scope.url, {"name": $scope.dataObject.name, "email": $scope.dataObject.country, "message": $scope.dataObject.comment}).
success(function(data, status) {
console.log(data);
$scope.status = status;
$scope.data = data;
$scope.result = data;
$scope.dataObject = {
name: "",
country: "",
comment: ""
};
})
$scope.comments.push(dataObject);
} else {
console.log("Form is not valid");
}
};
html file
<script type="text/ng-template" id="pages/forum.html">
<div ng-controller="Forum" class="forum-page">
<div class="col-lg-12">
<div id="comment-block">
<div id="comment-list" ng-repeat="comment in comments">
<div id="text-block">
<div class="comment-info name">{{comment.name}}</div>
<div class="comment-info" id="comment">{{comment.comment}}</div>
<div class="comment-info countries">{{comment.country}}</div>
</div>
</div>
<ng-form name="comment_box" id="comment-box">
<input type="text" class="comment-form" id="name" ng-model="dataObject.name" ng-minlength="2" ng-maxlength="20" ng-required="true" placeholder="Name">
<select class="comment-form" ng-model="dataObject.country" ng-options="x.country as x.country for x in options" ng-required="true">
<option value="">-- Choose Country --</option>
</select>
<textarea type="text" class="comment-form countries" ng-model="dataObject.comment" rows="6" cols="90" ng-minlength="1" ng-maxlength="300" ng-required="true" placeholder="Comment"></textarea>
<span class="comment-form" id="remain_amount_of_letters">{{300-dataObject.comment.length}} Left</span>
<button class="comment-form comment-button" ng-disabled="comment_box.$invalid" type="submit" ng-click="addComment(dataObject)">Place comment</button>
</ng-form>
</div>
</div>
</div>
</script>
- Ariën -:
Gelieve in het vervolg bij code de [code][/code]-tags gebruiken.
Hier kan je meer lezen over de mogelijke opmaakcodes.
Alvast bedankt!
Hier kan je meer lezen over de mogelijke opmaakcodes.
Alvast bedankt!
Gewijzigd op 30/11/2016 14:56:59 door - Ariën -
Waarom gebruik je geen file_put_contents?
<b>Warning</b>: file_put_contents() expects at least 2 parameters, 1 given in <b>/srv/disk8/2250145/submit.php</b> on line <b>12</b><br />
Name :
Email :
Message :
Wat moet ik hier doen, heb op internet gekeken, maar wordt daar niet echt wijzer van.
http://php.net/file_put_contents twee nodig zijn: De bestandsnaam en de inhoud die je wilt schrijven.
Een kwestie van lezen en vertalen. Je geeft één parameter op in file_put_content terwijl er volgens Nu slaat die de JSON op een file genaamd names.json, maar als ik Angular SPA ga refreshen dan verdwijnt de ingevoerde data. Wat doe ik verkeerd.