1

This is my html code:

<form style="width: 20%; margin: auto;" action="subscribe.php" method="post" id="subscribeToNews">
<fieldset>
<legend>Subscribe:</legend>
<label for="subName">First Name:</label><br /><input type="text" id="subName" name="subName" /><br />
<label for="subEmail">Email:</label><br /><input type="text" id="subEmail" name="subEmail"   /><br />
<input style="width: inherit;" type="submit" value="Subscribe" />
</fieldset>
</form>

This is the subscribe.php file:

<?php
$con = mysqli_connect('95.76.197.98','root','','accounts');
print_r($_POST);
if (isset($_POST["subName"]) && isset($_POST["subEmail"])){
$subUser = $_POST["subName"];
$subEmail = $_POST["subEmail"];
echo "$subUser"."<br />"."$subEmail";
}
?>

I have really tried a lot of things out there on the Internet and nothing seems to work for me. Any ideas?
Also looks like the get method works for this...

Emanuel Vintilă
  • 1,911
  • 4
  • 25
  • 35

2 Answers2

3

Could by related to your nginx configuration.

Try:

$post = file_get_contents("php://input");
wake-up-neo
  • 814
  • 7
  • 9
0

This should work:

<form style="width: 20%; margin: auto;" action="subscribe.php" method="post" id="subscribeToNews">
    <fieldset>
        <legend>Subscribe:</legend>
        <label for="subName">First Name:</label><br /><input type="text" id="subName" name="subName" /><br />
        <label for="subEmail">Email:</label><br /><input type="text" id="subEmail" name="subEmail"   /><br />
        <input style="width: inherit;" type="submit" value="Subscribe" />
    </fieldset>
</form>

<?php
$con = mysqli_connect('95.76.197.98','root','','accounts');

if($_POST) {
    $subName = mysqli_real_escape_string($con, strip_tags($_POST['subName']));
    $subEmail = mysqli_real_escape_string($con, strip_tags($_POST['subEmail']));

    if(isset($subName) && !empty($subName) && isset($subEmail) && !empty($subMail)) {
        echo 'Name: '.$subName.'<br> Email: '.$subEmail;
    }
}
?>
SuperDJ
  • 7,488
  • 11
  • 40
  • 74
  • Nothing seems to work, so I went with form method GET and php $_GET. It works like a charm... Thanks for the struggle though, but I will go on with get, as there is no sensitive information included. – Emanuel Vintilă Apr 06 '14 at 09:56