Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-这是在If语句中传递多个参数的正确方法吗_Php - Fatal编程技术网

PHP-这是在If语句中传递多个参数的正确方法吗

PHP-这是在If语句中传递多个参数的正确方法吗,php,Php,正在尝试创建一个retieve/recover表单,用户可以在该表单中键入自己的名字和姓氏以检索电子邮件地址。我不确定是否需要使用数组来执行此操作,或者这种方式是否也可以,但我得到了一个语法错误 <br /> <br /><p3>Retrieve User Information</p3> <br /> <br /> <?php if(isset($_POST['fist_name'], $_POST['last

正在尝试创建一个retieve/recover表单,用户可以在该表单中键入自己的名字和姓氏以检索电子邮件地址。我不确定是否需要使用数组来执行此操作,或者这种方式是否也可以,但我得到了一个语法错误

<br /> <br /><p3>Retrieve User Information</p3> <br /> <br />
 <?php


if(isset($_POST['fist_name'], $_POST['last_name']) === true && empty($_POST['first_name'] , $_POST['last_name']) === false){

 if(email_exists($_POST['email']) === true) {
retrieve('email');
 }

 }
 else{
$errors[] = '<p1 class="postad_msg">Sorry, we could not find that email address!</p1>';
 }
 ?>
 <form method="post" action="retrieve">
 <fieldset>              
     <label for="first_name">First Name * : </label>
     <input placeholder="Your first name" type="text" name="first_name" size="30" maxlength="30" value="<?php echo htmlentities($first_name); ?>" /><br /><br />

     <label for="last_name">Last Name * : </label>
     <input placeholder="Your last name" type="text" name="last_name" size="30" maxlength="30" value="<?php echo htmlentities($last_name); ?>" /><br /><br />

 </fieldset>
 <fieldset class="center1">
     <input class="submit" type="submit" name="submit" value="Retrieve Email" />
 </fieldset>                        
<?php echo output_errors($errors); ?>
    <?php echo output_message($message);?>
 </form>

<?php 
   }
else{
header('Location: index');
exit();
}
    ?>     


检索用户信息

姓名*:
empty()
不接受多个参数

您需要以这种方式重写:

... empty($_POST['first_name']) === false && empty($_POST['last_name']) === false) {

不需要嵌套条件。只需使用:

if( (isset($_POST['first_name']) && $_POST['first_name']) &&
    (isset($_POST['last_name']) && $_POST['last_name']) &&
    (isset($_POST['email']) && $_POST['email']) ) {

}
请注意,您的名字有一个拼写错误


希望这有帮助

我写得很快,所以没有测试它

但我想你会发现你的错误

<br /> <br /><p3>Retrieve User Information</p3> <br /> <br />
 <?php
  if (isset($_POST['submit'])) {
 $mode_allowed = array('email', 'passwd');
 if (isset($_GET['mode']) && in_array($_GET['mode'], $mode_allowed)){ 

if(isset($_POST['fist_name']) && isset($_POST['last_name']) && !empty($_POST['first_name']) && !empty($_POST['last_name']) ){

 if(email_exists($_POST['email']) ) {
retrieve('email');
 }

 }
 else{
$errors = '<p1 class="postad_msg">Sorry, we could not find that email address!</p1>';
 }


?>
 <form method="post" action="">
 <fieldset>              
     <label for="first_name">First Name * : </label>
     <input placeholder="Your first name" type="text" name="first_name" size="30" maxlength="30" value="<?php echo htmlentities($first_name); ?>" /><br /><br />

     <label for="last_name">Last Name * : </label>
     <input placeholder="Your last name" type="text" name="last_name" size="30" maxlength="30" value="<?php echo htmlentities($last_name); ?>" /><br /><br />

 </fieldset>
 <fieldset class="center1">
     <input class="submit" type="submit" name="submit" value="Sign Up For A Vegizzle Account" />
 </fieldset>                        
<?php if (isset($errors)) { echo output_errors($errors); } ?>
    <?php if (isset($message)) {echo output_message($message); }?>
 </form>
 <?php
    }

else{
header('Location: index');
exit();
}
  }
else {
    return;
}
?>


检索用户信息

姓名*:
我是否需要嵌套空($\u POST['first\u name'])==false&&empty($\u POST['last\u name'])==false)否,因为您的if语句中只有&。顺便说一句,您不需要同时使用empty()和isset()。只需使用empty(),它会检查变量是否已设置且不是null/empty string/0。我知道,我知道……但您必须提醒初学者这些规则!我接受了答案,但它不允许我投票。它说我需要15个声誉才能这样做。很抱歉不过我还是接受了答案。再次感谢!感谢大家对拼写错误的了解,但坦率地说,这是由于缺乏PHP方面的知识,代码看起来有点让我困惑。我没有一个名为first_last??Oops的变量,它应该是“last_name”(已修复)。最好是解释您已修复的内容,并提供一个简洁的示例,而不是期望有人比较完整的代码块以找出您已修改的内容,然后猜测原因。是的,您是对的,当我想回答任何问题时,我都会这样做