有人可以告诉我下面filter_var
函数中对validateEmail
的调用有什么问题吗?如果我发表评论,可以在FireBug或Chrome控制台中看到该行hohum
,另一方面Chrome报告的内容如下:This request has no response
。来自java背景,我想知道我是否需要include
一些库用于filter_var函数?
<?php
function validateInput($data, $con) {
$data = trim($data);
$data = stripslashes($data);
$data = mysqli_real_escape_string($con, $data);
return $data;
}
function validateEmail($email, $con) {
$email = validateInput($email, $con);
if (filter_var($email, FILTER_VALIDATE_EMAIL) {
return $email;
} else {
return "";
}
}
function validateText($text, $con) {
$text = validateInput($text, $con);
if(preg_match('/[^a-zA-Z]/', $text) == 0) {
return $text;
} else {
return "";
}
}
$hostname="localhost";
$username="my_user";
$password="my_psswd";
$dbname="my_db";
$con = mysqli_connect($hostname, $username, $password, $dbname);
if (!$con) {
header('HTTP', true, 500);
echo('Could not connect: ' . mysql_error());
} else {
echo ("Hohum: ");
}
?>
答案 0 :(得分:0)
您错过了)
,
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {