简体   繁体   English

PHP $ _POST返回空值

[英]PHP $_POST returns null values

This is my html code: 这是我的html代码:

<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: 这是subscribe.php文件:

<?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. 我确实在Internet上尝试了很多方法,但似乎没有任何效果对我有用。 Any ideas? 有任何想法吗?
Also looks like the get method works for this... 看起来get方法也适用于此...

Could by related to your nginx configuration. 可能与您的nginx配置有关。

Try: 尝试:

$post = file_get_contents("php://input");

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;
    }
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM