Necesita mostrar el nombre de usuario en el cuadro combinado después de iniciar sesión correctamente en PHP

i want to show the username after successful login in a combobox.

<?php
$val = $_POST['applicant']?:'';

$sql = "SELECT username FROM `user` where password = '".$_SESSION['password']."'";
$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>';

}
?>

preguntado el 12 de febrero de 14 a las 06:02

1 Respuestas

prueba este

$val = "";
if(isset($_POST['applicant']))
{
  $val = $_POST['applicant'];
}

$sql = "SELECT username FROM `user` where password = '".$_SESSION['password']."'";
$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>';

ACTUALIZACIÓN

actualización para still no result comentario

you can use trim you post value and check it in table user en columna username mannualy that exists in database or not

 $val = "";
    if(isset($_POST['applicant']))
    {
      $val = trim($_POST['applicant']);
    }
echo $val;


}

Respondido 12 Feb 14, 06:02

i think issue is not clear. i have a table named "user" that has username and password column. i am loging using this two value. after successfully login i want to insert the username as applicant field in another table. - Basudev

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.