我在成功登录后面临使用用户名的问题。
以下是登录代码:
<?php
//validation error
if(isset($_REQUEST['validationError']))
{
if($_REQUEST['validationError']==1)
{
$username='Username required';
}
if($_REQUEST['validationError']==2)
{
$password='Password required';
}
if($_REQUEST['validationError']==3)
{
$not_match='User not exist. Please give correct information';
}
}
?>
<p><span style="color:red;display:<?php echo isset($not_match)?'block':'none' ?>"><?php echo isset($not_match)?$not_match:''; ?><span></p>
<p><input size="40px" type="text" name="username" value="<?php echo isset($_POST['username'])?$_POST['username']:''; ?>" value="" placeholder="Username"></p>
<p><span style="color:red;display:<?php echo isset($username)?'block':'none' ?>"><?php echo isset($username)?$username:''; ?><span></p>
<p><input size="40px" type="password" name="password" value="" placeholder="Password"></p>
<p><span style="color:red;display:<?php echo isset($password)?'block':'none' ?>"><?php echo isset($password)?$password:''; ?><span></p>
<p class="submit"><input type="submit" name="submit" value="Login"></p>
</form>
以下是登录检查的代码:
if($username !='' && $password !='')
{
include('database_connection.php');
$result = mysql_query("SELECT * from user WHERE username='$username' AND password='$password'");
if(mysql_num_rows($result)==0)
{
$validationError=3;
}
}
if(isset($validationError) && $validationError==0)
{
//session set
session_start();
$_SESSION['isLogin']=1;
//redirect to homepage with successfull message
header("Location:$base_url/index.php?validationError=$validationError");
}
else
{
//redirect to login_form with msg
header("Location:$base_url/login_form.php?validationError=$validationError");
}
现在我想在下拉框字段中获取用户名值。
下面是代码
$sql = "SELECT username FROM `user`";
$res = mysql_query($sql);
while ($row1 = mysql_fetch_array($res)) {
$selected = ($val == $row1['username'] ? 'selected="selected"' : '');
echo '<option value ="' . $row1['username'] . '" '. $selected .'>' . $row1['username'] . '</option>';
}
?>
但我在这个领域没有任何价值。