Solution 1 :

The issue ended up being in the .htaccess as the URL was being redirected to remove the .php and this was causing issues with POST data being lost. This was the code:

RewriteCond %{THE_REQUEST} /([^.]+).php [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [NC,L]

This is RewriteCond %{REQUEST_METHOD} !POST fixed the problem.

Problem :

So I have a HTML file with the following form:

    <!DOCTYPE html>
<html lang="en" dir="ltr">
    <meta charset="utf-8">
    <form action="pringles.php" method="post">
      First name:<br>
      <input type="text" name="firstname" value="Mickey">
      Last name:<br>
      <input type="text" name="lastname" value="Mouse">
      <input type="submit" value="Submit">

Then I have a PHP file names pringles.php which contains the following code:

// server, username, password, db, port
$servername = "********";
$username = "*******";
$password = "********";
$dbname = "*********";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

foreach ($_POST as $key => $value) {
  $postdata2 = $postdata2 . "Field ".htmlspecialchars($key)." is ".htmlspecialchars($value) . "////";

$sql = "INSERT INTO `test`(`text`) VALUES ('{$postdata2}')";
if ($conn->query($sql) === TRUE) {
  echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;

However, when I submit the form it inserts a row into my database but the text field is empty. The post variables are not being sent for some reason. Additionally, I have another .php file where a form works perfectly. They are in the same folder and everything, therefore I don’t understand why this isn’t working.



Comment posted by u_mulder


Comment posted by Funk Forty Niner

Why would you enter all POST’s into the one column? Or are you wanting to create a new column for each of them? What is the db schema/column type?

Comment posted by Funk Forty Niner

In addition to what @u_mulder mentioned, use what they suggested and then dump

Comment posted by Tim Rumit

@u_mulder its shows NULL

Comment posted by u_mulder