0

我正在尝试根据用户是“新”还是“现有”来更改我的登录表单。例如,如果选择“现有用户”仅显示“用户名”和“密码”输入字段。选择“新用户”会得到“用户名”、“电子邮件”、“密码”和“密码确认”。

<select id="login_type" name="logintype">
 <option value="Register">a new user</option> 
 <option value="Login">an existing user</option>
</select> 

尝试了下面的代码,但是当它在我的 if else 中读取我的 html 表单时它卡住了。我能做什么?

<?php
if (isset($_POST['login_type']) && $_POST['login_type'] == 'an existing user') 
{ 
<div>
    <label for="uname_input">Username:</label>
    <input id="uname_input" name="uname" type="text" required="required" placeholder="Enter your username"/>
    <br />
    <label for="pass_input">Password:</label>
    <input id="pass_input" name="passwd" type="password" required="required" placeholder="Enter your password"/>
</div> 

<input id="submit_login" type="submit" value="Submit" /> 

} 
else 
{ 
    <div class="shownew">
        <label for="em_input">Email:</label>
        <input id="em_input" name="email" type="text"  placeholder="Enter a valid email address"/>
    </div>
    <div>
        <label for="uname_input">Username:</label>
        <input id="uname_input" name="uname" type="text" required="required" placeholder="Enter your username"/>
        <br />
        <label for="pass_input">Password:</label>
        <input id="pass_input" name="passwd" type="password" required="required" placeholder="Enter your password"/>
    </div>
    <div class="shownew">
        <label for="pass2_input">Confirm:</label>
        <input id="pass2_input" name="passwd2" type="password" placeholder="Repeat your password"/>
    </div> 
    <input id="submit_login" type="submit" value="Submit" /> 
}

if (isset($_GET['error']))
{
  $errmsg = '';
  switch ($_GET['error'])
  {
  case 1: $errmsg = 'Passwords entered do not match one another.'; break;
  case 2: $errmsg = 'Username already exists in the database. Please choose   a           different username.'; break;
  case 3: $errmsg = 'The username or password you entered is incorrect. Please try again.'; break;
  case 4: $errmsg = 'Invalid login mode. Please reload the page and try again.'; break;
  case 5: $errmsg = 'Unexpected error processing login. Please try again'; break;
  default: $errmsg = 'An unknown error occurred. Please try again in a few minutes.'; break;
  }
  print '<p class="errmsg">' . $errmsg . '</p>';
}
?>
4

3 回答 3

1

看起来您缺少 php 开始/结束标签:

if (isset($_POST['login_type']) && $_POST['login_type'] == 'an existing user') 
{ 
<div>

应该

if (isset($_POST['login_type']) && $_POST['login_type'] == 'an existing user') 
{
?> 
<div>

ETC...

于 2013-05-02T17:30:49.237 回答
0
<select id="login_type" name="logintype">
  <option value="Register">a new user</option> 
  <option value="Login">an existing user</option>
</select> 

logintype is either Register or Login. The description has nothing to do here.

于 2013-05-02T18:12:59.290 回答
0

选择名称是'logintype'并忘记关闭)在isset

改变

<?php
if (isset($_POST['login_type']) && $_POST['login_type'] == 'an existing user') 
{ 

<?php
if (isset($_POST['logintype']) && $_POST['logintype'] == 'an existing user') 
{ 
于 2013-05-02T17:37:01.543 回答