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

5
  • 3
    Other than your if not closed, I don't see anything wrong. Commented Apr 6, 2014 at 7:05
  • How can you say it returns NULL value? Did you try print_r($_POST) ? Commented Apr 6, 2014 at 7:05
  • 1
    @ICanHasCheezburger is right. Enable error reporting Commented Apr 6, 2014 at 7:06
  • 1
    check if post array has value print_r($_POST); Commented Apr 6, 2014 at 7:22
  • I checked it... it returns Array (). Commented Apr 6, 2014 at 9:57

2 Answers 2

3

Could by related to your nginx configuration.

Try:

$post = file_get_contents("php://input");
Sign up to request clarification or add additional context in comments.

1 Comment

No, it's not. I have other forms and POST works perfectly there.
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;
    }
}
?>

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.