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

时间:2014-01-21 23:05:26

标签: php

尝试创建一个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();
}
    ?>     

提前致谢!

3 个答案:

答案 0 :(得分:1)

empty()不会使用多个参数。

您需要以这种方式重写:

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

答案 1 :(得分:0)

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

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

}

请注意,您在first_name中输入了拼写错误。

希望这有帮助!

答案 2 :(得分:0)

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

但我认为你会发现你的错误

<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;
}
?>
相关问题