我试图让PHP将我的选择选项作为变量读取,然后根据用户选择回显特定页面。
登录系统功能正常但只能将我登录到一个页面。
<form action="login.php" method="POST">
<table cellspacing="10">
<tr>
<td>Email: </td>
<td><input type='text' name='email'/></td>
</tr>
<tr>
<td>Password: </td>
<td><input type='password' name='password'/></td>
</tr>
<tr>
<td>Event: </td>
<td>
<select name="event">
<option><?php echo $title?></option>
<option><?php echo $title2?></option>
</select>
</td>
</tr>
</table>
<br />
<button class="button" type='submit' name='Submit' value='Submit' />Login</button>
</form>
<?php
if (!empty($email) && !empty($password)) {
$pdo = getPdo();
$statement = $pdo->prepare('SELECT * FROM awdawda WHERE email=:email;');
$statement->bindParam(':email', $email);
$statement->execute();
$data = $statement->fetch();
$pdo = null;
if (!empty($data)) {
$dbemail = $data['email'];
$dbpassword = $data['password'];
$dbfullname = $data['fullname'];
if ($password == $dbpassword) {
$_SESSION['fullname'] = $dbfullname;
$_SESSION['email'] = $email;
$_SESSION['password'] = $password;
if ($_POST['event']) {
$event1=$title;
echo '<script type="text/javascript">window.location = "http://awda/adwa/awd1.php" </script>';
}
if ($_POST['event']) {
$event2=$title2;
echo '<script type="text/javascript">window.location = "http://awdaw/awda/adwa.php" </script>';
}
}
echo '<div style="padding: 10px;">Login Failed: Password Incorrect</div>';
}
echo '<div style="padding: 10px;">User not found</div>';
}
?>
这是我用来登录的代码。我遗漏了它上面的东西,因为它现在一切正常。
答案 0 :(得分:1)
您必须为options
代码
select
赋予价值
<select name="event">
<option value="value1"><?php echo $title?></option>
<option value="value2"><?php echo $title2?></option>
</select>
并且必须根据这些值更新您的php逻辑
if ($_POST['event'] == "value1") {
$event1=$title;
echo '<script type="text/javascript">window.location = "http://awda/adwa/awd1.php" </script>';
}
if ($_POST['event'] == "value2") {
$event2=$title2;
echo '<script type="text/javascript">window.location = "http://awdaw/awda/adwa.php" </script>';
}