gpt4 book ai didi

php - if(isset($_POST()) 始终为 false

转载 作者:行者123 更新时间:2023-11-29 21:15:20 25 4
gpt4 key购买 nike

由于某种原因,$_POST 数组没有更新,不知道为什么。

这是我的代码,写在名为database.php的文件中:

$user = 'root';
$password = '';
$db = 'comments_schema';
$host = 'localhost:3306';

$mysqli = mysqli_connect('localhost', $user, $password, $db);
$field1_name = "";

if(isset($_POST['field1_name'])) {
$field1_name = $_POST['field1_name'];
}
else {
echo "something is wrong here";
}
$field_name = mysqli_real_escape_string($mysqli, $field1_name);

$sql = 'INSERT INTO parent_comment(commentid, comment) VALUES
('.commentid.', '.$field_name.')';
$result = $mysqli->query($sql);

这是我的 index.html 部分:

<form action="database.php" method="post">
Comments: <input type="text" name="field1_name"/>
<input type="Submit" name="Submit" value="submit query"/>
</form>

在这种情况下 isset 总是返回 false 有什么原因吗?

最佳答案

编辑:我不知道是否是这种情况,但请检查 php.ini 中的 max_input_vars 值是否为低数字

php_value max_input_vars 6000 //6K is the value you need


//first if checks if the form was submitted first, so you don't always display the error.
if(isset($_POST['Submit'])){
$user = 'root';
$password = '';
$db = 'comments_schema';
$host = 'localhost:3306';

$mysqli = mysqli_connect('localhost', $user, $password, $db);
$field1_name = $_POST['field1_name'] ?? ""; //Use only if you are using PHP 7+ Otherwise leave the code as it was but wrap it inside the outer if.

if(empty($field_name)){
echo "something is wrong here";
}
$field_name = mysqli_real_escape_string($mysqli, $field1_name);

$sql = 'INSERT INTO parent_comment(commentid, comment) VALUES ('.commentid.', '.$field_name.')';
$result = $mysqli->query($sql);
}

更多信息:https://lornajane.net/posts/2015/new-in-php-7-null-coalesce-operator

关于php - if(isset($_POST()) 始终为 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36002766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com