简体   繁体   English

PHP的filter_var问题

[英]filter_var php question

I am making a quick little email script for a contact form and these variable aren't being set( $firstName and $lastName ). 我正在为联系表单制作一个快速的小电子邮件脚本,并且未设置这些变量( $firstName$lastName )。

$firstName = filter_var($_POST['firstName'], FILTER_SANITIZE_STRING);
$lastName = filter_var($_POST['lastName'], FILTER_SANITIZE_STRING);

Note I am a beginner at php 注意我是php的初学者

You're a beginner? 你是初学者吗? Well, hats off to you for using data validation from the get-go! 好吧,从一开始就对您使用数据验证表示感谢!

can you put this below those two lines and give us the output? 您可以将其放在这两行下面并提供给我们输出吗?

var_dump($firstName, $lastName, $_POST);

As you have mention that you are beginner at php, I think you have not set form method. 正如您所提到的,您是php的初学者,我认为您尚未设置form方法。 By default form method is GET and you are trying to fetch value using POST method. 默认情况下,表单方法是GET,并且您尝试使用POST方法获取值。 So either you change your form method to POST or set variable as below : 因此,您可以将表单方法更改为POST或设置变量,如下所示:

$firstName = filter_var($_GET['firstName'], FILTER_SANITIZE_STRING); $ firstName = filter_var($ _ GET ['firstName'],FILTER_SANITIZE_STRING); $lastName = filter_var($_GET['lastName'], FILTER_SANITIZE_STRING); $ lastName = filter_var($ _ GET ['lastName'],FILTER_SANITIZE_STRING);

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

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