PHP 最后一行语法错误?
<?php
if (!isset($_POST['ign'], $_POST['email'])) {
if($_POST['ign'] && $_POST['email']){
echo "Please fill out all of the fields!";
die;
}
if (empty($_POST['ign']) || empty($_POST['email'])) {
echo ("Please enter all of the values!");
die;
}
if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$email = $_POST['email'];
echo ("Thanks, " . htmlentities($_POST['ign']) . ", you will recieve an email when the site is complete!");
}
else {
echo "Your email was invalid!";
die;
}
?>
我在最后一行遇到语法错误,其中 ?>;是..
另外,只是一个随机的旁注,任何人都可以教我如何将其插入到我的代码中吗?
$valid = (bool)preg_match('/^[a-zA-Z0-9]{1,30}$/', $_POST['username']);
它只是
if ($valid == TRUE) {
////////
}
或者声明该变量已经在运行它?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
第一个
if
块中缺少结束大括号}
。You have a missing ending brace
}
in the firstif
block.如果不遵循脚本的逻辑,您将有五个左大括号 { 和四个右大括号 }
Without following the logic of your script, you have five open braces { and four closed braces }
您在
if (!isset($_POST['ign'], $_POST['email']))
行周围打开两个作用域(使用{
),因此您需要在需要的地方关闭悬空的那个。You open two scopes (with
{
) around theif (!isset($_POST['ign'], $_POST['email']))
line, so you need to close the dangling one where you need to.您可以从上一个问题 验证电子邮件错误 中获取代码,并添加测试用户名的长度并检查用户名是字母数字,如下所示:
注意:如果我假设
$_POST['ign']
是您在该行中要说的内容(bool)preg_match('/^[a-zA-Z0-9]{1,30}$/', $_POST['username'])
,错误...发布更多详细信息关于你需要什么,我会更新我的答案。You can take the code from your last question, Validate Email Error , and add a test for length of username and check username is alphanumeric like this:
Note: If my assumption that
$_POST['ign']
is what you meant to say to in the line(bool)preg_match('/^[a-zA-Z0-9]{1,30}$/', $_POST['username'])
,is wrong ... post more details on what you need and I'll update my answer.