0

I would like to send a data to php but i don't know why it doesn't work

Here is my code

html

<!DOCTYPE html>

<html>
<title>web </title>
<body>
<script>
    $(document).ready(function()
    {
      $.post("loadWebGenerator.php",
        {
            data: "received"
        }
      );
    })
</script>
<form oninput="getSubjectList()">
    <input list="subjectName">
        <datalist id="subjectName">
        </datalist>
</form>
</body>
</html>

php

include('../Sql.php');
$received = $_post['data'];
file_put_contents("log.txt",$received);

Thank you

Siu Harry
  • 41
  • 1
  • 1
  • 2
  • It should be `$_POST[data]` instead of `$_post['data']` as `$_POST` is case sensitive. – Lal Jun 13 '17 at 16:55

1 Answers1

1

The variable names are case sensitive.

The code should be like this:

include('../Sql.php');
$received = $_POST['data'];
file_put_contents("log.txt",$received);

By the way, it's better to make it a bit more reliable:

include('../Sql.php');
if (!empty($_POST['data']) {
  $received = $_POST['data'];
  file_put_contents("log.txt",$received);
}
Mojtaba
  • 4,852
  • 5
  • 21
  • 38