1

I'm using the following code :-

Javascript :-

var t_sql="SELECT * FROM `compliance_report`;";

  const options = {
      method: 'POST',
      headers: {'Content-Type': 'application/json'},
      body: JSON.stringify( {sql: t_sql} )  
  };
  fetch( 'test3.php', options )
      .then( response => response.json() )
      .then( response => {
         console.log(response);
      } );

The PHP code is just to echo back the Post data

:-

<?php
$sql=$_POST['sql'];
$au=json_encode($sql);
echo $au;
?>

But all I am getting back is NULL? can anyone tell me what is wrong. I ultimately want to run the query and echo back the result but the server is reporting the $_POST as empty?

Shizaro
  • 11
  • 2
  • For json you need to use 'php://input', not $_POST. Does the following thread help? https://stackoverflow.com/questions/18866571/receive-json-post-with-php – qrsngky Apr 07 '22 at 12:43

0 Answers0