Jump to content

the user name cannot be shown


kof20012

Recommended Posts

hi there,

 

i got problem, when i made the login, the name of the user is not shown on the welcome messge :s

anone can hell me out?

 

regards

 

the code

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function tdmouseover(el) {
el.style.color = "#666666"
el.style.backgroundColor = "#c0c0c0"
}
function tdmouseout(el) {
el.style.color = "#666666"
el.style.backgroundColor = "#F8F8F8"
}
</script>
</head>
<body>
<table width="160" border="0" cellspacing="0" cellpadding="0" bgcolor="#F8F8F8">
<tr bgcolor="#66CCCC">
<td width="5" height="10"><font color="#ffffff"> </font></td>
<td width="150"><div align="center"><font color="#ffffff" size="2" face="Verdana, Arial, Helvetica, sans-serif">
    	<strong>Membership</strong></font></div></td>
    <td width="5"> </td>
</tr>

<tr>
<td width="5"> </td>
    <td align="left" valign="top">

<?php

include $_SERVER['DOCUMENT_ROOT'].'/TFC/session.php';

session_start();
if($_SESSION['login']==true)
{
//Mostrar links logout

$nome=$_SESSION['primeiro_nome'];

echo '-Welcome'.$nome.'!<br>';
echo '-<a href="/TFC/members.php">Members Area </a><br>';
echo '-<a href="/TFC/logout.php">Logout </a>';

}else{

//login formulario

echo '-<a href="/TFC/RegistoUtilizadores.php" target="_blank" >Registo</a><br>';
echo '-<a href="/TFC/login_form.php" target="_blank">Membro Login </a><br>';
echo '-<a href="/TFC/lostpw.php">Lost Password? </a>';
	}
?>
</td>

</tr>
<tr>
<td width="5" height="10" ><font color="ffffff"> </font></td>
<td width="150"> </td>
<td width="5"> </td>
</tr>
</table>
<hr size="1" />
</body>
</html>

 

the session file

<?php

session_start();

session_name('MyPHPSite');
header("Cache-control: private"); //para IE


function login_check()
{
if($_SESSION['login'] != true)
	{
	titulo("Login Required!");
	include $_SERVER['DOCUMENT_ROOT'].'/TFC/login_form.php';
	$_SESSION['primeiro_nome'];
	corpo();
	}
}

function admin_check()	
{
if($_SESSION['acesso_admin'])
	{
titulo("acess denied");
echo "<center>this area is restricted for administrators only!";
corpo();	
exit();

	}
}



?>

Link to comment
https://forums.phpfreaks.com/topic/118830-the-user-name-cannot-be-shown/
Share on other sites

in the login.php

 

<?php
include $_SERVER['DOCUMENT_ROOT']. '/TFC/layout.php';

$ligacao=mysql_pconnect('localhost', 'root', '') or die("Problemas de ligaçao");
mysql_select_db("TFC", $ligacao);

switch($_REQUEST['req'])
{

case "validate":

$validate=@mysql_query("select * from membros where username='{$_POST['username']}' and password ='{$_POST['password']}' and verified='1'");
//echo "select * from membros where username='{$_POST['username']}' and password = md5('{$_POST['password']}') and verified='1'";
if(mysql_num_rows($validate)==1)
	{
	while ($rows=mysql_fetch_assoc($validate))
		{
		$_SESSION['login']=TRUE;
		$_SESSION['userid']=$row['id'];
		$_SESSION['primeiro_nome']=$row['primeiro_nome'];
		$_SESSION['ultimo_nome']=$row['ultimo_nome'];
		$_SESSION['Email']=$row['Email'];



		if($row['acesso_admin']==1)
			{
			$_SESSION['acesso_admin']=TRUE;
			}

		$login_time=mysql_query("UPDATE membros SET ultimo_login=now() WHERE id='{$row['id']}'");

		}
	header("location: /TFC/loggedin.php");

		}else{

		titulo ("Login Fallhou!...");

		echo'<p align=center>login falhou</p><p align=center>if you have already join our website, you may need to validate your email.'.
			'Please check you email for instructions.';

			corpo();

		}

		break;

		default:

		titulo("Login!");

		include $_SERVER['DOCUMENT_ROOT'].'/TFC/login_form.php';

		corpo();

		break;

		}



?>		

while ($rows=mysql_fetch_assoc($validate))
		{
		$_SESSION['login']=TRUE;
		$_SESSION['userid']=$row['id'];
		$_SESSION['primeiro_nome']=$row['primeiro_nome'];
		$_SESSION['ultimo_nome']=$row['ultimo_nome'];
		$_SESSION['Email']=$row['Email'];
}

 

You're using $row when you should be using $rows.

while ($rows=mysql_fetch_assoc($validate))
		{
		$_SESSION['login']=TRUE;
		$_SESSION['userid']=$row['id'];
		$_SESSION['primeiro_nome']=$row['primeiro_nome'];
		$_SESSION['ultimo_nome']=$row['ultimo_nome'];
		$_SESSION['Email']=$row['Email'];
}

 

You're using $row when you should be using $rows.

We can quite clearly see you should be using $rows but you're not.
while ($rows=mysql_fetch_assoc($validate))
		{
		$_SESSION['login']=TRUE;
		$_SESSION['userid']=$rows['id'];
		$_SESSION['primeiro_nome']=$rows['primeiro_nome'];
		$_SESSION['ultimo_nome']=$rows['ultimo_nome'];
		$_SESSION['Email']=$rows['Email'];
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.