ItSolutionStuff.com

PHP - I Can't get the $_POST Values on Ajax Request

By Hardik Savani • May 14, 2024
PHP

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...

Tags: PHP
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Get All Dates Between Two Dates in PHP?

Read Now →

How to Get Full Day Name from Date in PHP?

Read Now →

How to Subtract Hours from DateTime in PHP?

Read Now →

PHP Add Hours to Datetime Example

Read Now →

How to Add Year to Date in PHP?

Read Now →

PHP Curl PUT Request Example Code

Read Now →

PHP Curl POST Request with Headers Example

Read Now →

PHP CURL Post Request with Parameters Example

Read Now →

Codeigniter Ajax Infinite Scroll Pagination Example

Read Now →

PHP - Getting Started PHPUnit Test Example

Read Now →

How to Remove White Space from String in PHP?

Read Now →

How to Get php.ini File Path in Ubuntu?

Read Now →

How to use Google Maps API with JQuery PHP?

Read Now →