简体   繁体   中英

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 = filter_var($_POST['firstName'], FILTER_SANITIZE_STRING);
$lastName = filter_var($_POST['lastName'], FILTER_SANITIZE_STRING);

Note I am a beginner at 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. By default form method is GET and you are trying to fetch value using POST method. So either you change your form method to POST or set variable as below :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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