PHP - I Can't get the $_POST Values on Ajax Request
I want to share these posts with you because when I was working on native PHP and Ajax Post request(Specially AngularJS Post request) at that time I can't get a Post value on the form to submit. That's why I would like to share this post. I also want to tell you i was working on my Ubuntu 14.04. I did try a lot but I can't get value.
At last find stuff on how to solve this issue, I did use "file_get_contents('php://input')" that way I could get the POST value in a JSON object and I also decode json value using "json_decode()". So let's try this way :
Solution:
<?php
$post = file_get_contents('php://input');
$post = json_decode($post);
$sql = "INSERT INTO items (title) VALUES ('".$post->title."')";
$result = $mysqli->query($sql);
?>
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Get All Dates Between Two Dates in PHP?
- How to Get Full Day Name from Date in PHP?
- How to Subtract Hours from DateTime in PHP?
- PHP Add Hours to Datetime Example
- How to Add Year to Date in PHP?
- PHP Curl PUT Request Example Code
- PHP Curl POST Request with Headers Example
- PHP CURL Post Request with Parameters Example
- Codeigniter Ajax Infinite Scroll Pagination Example
- PHP - Getting Started PHPUnit Test Example
- How to Remove White Space from String in PHP?
- How to Get php.ini File Path in Ubuntu?
- How to use Google Maps API with JQuery PHP?