在PHP中,我应该在提交按钮中使用什么过滤器? [英] In PHP, what filter should I use in a submit button?
问题描述
在
<form action="" method="post" role="form">
我使用
if (filter_input(INPUT_POST, 'send_comment'))
它总是返回False / NULL但是如果使用这两个中的任何一个
It always return False/NULL but if any of these two are used
if (filter_has_var(INPUT_POST, 'send_comment'))
或
if (isset($_POST['send_comment']))
有效。这是PHP中的错误(我使用XAMPP PHP 5.6)?或者我的代码有问题吗?
It works. Is it a bug in PHP (I use XAMPP PHP 5.6)? Or is there something wrong with my codes?
<?php
if (filter_has_var(INPUT_POST, 'send_comment')) {
$post_id = filter_input(INPUT_GET, 'p_id', FILTER_SANITIZE_STRING);
$user_name = filter_input(INPUT_POST, 'comm_author', FILTER_SANITIZE_STRING);
$user_email = filter_input(INPUT_POST, 'comm_email', FILTER_VALIDATE_EMAIL);
$user_comment = filter_input(INPUT_POST, 'comm_content', FILTER_SANITIZE_STRING);
$insertQuery = "INSERT INTO comments (comm_post_id, comm_author, comm_email, comm_content, comm_status, comm_date) ";
$insertQuery .= "VALUES ({$post_id}, '{$user_name}', '{$user_email}', '{$user_comment}', 'unapproved', now())";
$executeQuery = mysqli_query($conn, $insertQuery);
confirm($executeQuery);
}
?>
<div class="well">
<h4>Leave a Comment:</h4>
<form action="" method="post" role="form">
<div class="form-group">
<label for="comm_author">Name</label>
<input type="text" class="form-control" name="comm_author">
</div>
<div class="form-group">
<label for="comm_email">Email</label>
<input type="email" class="form-control" name="comm_email">
</div>
<div class="form-group">
<label for="comm_content">Comments</label>
<textarea class="form-control" name="comm_content" rows="3"></textarea>
</div>
<button type="submit" name="send_comment" class="btn btn-primary">Submit</button>
</form>
</div>
我尝试了什么:
尝试使用filter_input(INPUT_POST,'send_comment')但它不起作用,但如果我使用isset($ _ POST,'send_comment')或者filter_has_var(INPUT_POST,'send_comment')它可以工作。
What I have tried:
Tried using filter_input(INPUT_POST, 'send_comment') but it does not work, but if I use isset($_POST, 'send_comment') or filter_has_var(INPUT_POST, 'send_comment') it works.
推荐答案
_ POST [' send_comment']))
_POST['send_comment']))
它有效。这是PHP中的错误(我使用XAMPP PHP 5.6)?或者我的代码有问题吗?
It works. Is it a bug in PHP (I use XAMPP PHP 5.6)? Or is there something wrong with my codes?
<?php
if (filter_has_var(INPUT_POST, 'send_comment')) {
post_id = filter_input(INPUT_GET,' p_id',FILTER_SANITIZE_STRING);
post_id = filter_input(INPUT_GET, 'p_id', FILTER_SANITIZE_STRING);
user_name = filter_input(INPUT_POST,' comm_author',FILTER_SANITIZE_STRING);
user_name = filter_input(INPUT_POST, 'comm_author', FILTER_SANITIZE_STRING);
这篇关于在PHP中,我应该在提交按钮中使用什么过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!