2014-04-01 2 views
-4

이 코드는 여기에서 완벽하게 잘 작동합니다. 내가하고 싶은 것은 $ userName에 이미 저장되어있는 FirstName과 LastName (SESSION 사용)을 전달하는 것이다. 이름과 성은 실제로 로그인 할 때 데이터베이스에서 검색됩니다. 나는 모든 페이지에 이름과 성 쇼가 한 번에 기록하고 싶지 ... 감사합니다세션 변수가 다음 페이지로 동적으로 전달됨

<table width="800" border="0" align="center" cellpadding="0" cellspacing="0"> 
<tr> 
<td><?php 
$DisplayForm = TRUE; 
$errors = 0; 

if(isset($_POST['uname']) && isset($_POST['pass'])) { 
include("dbconnect.php"); 
if($DBConnect !== FALSE){ 
$SQLstring = "SELECT userid, first_name, last_name FROM users WHERE username ='". 
$_POST['uname']. "' and password = '".md5($_POST['pass'])."'"; 
$DisplayForm = FALSE; 
$QueryResult = @mysql_query($SQLstring, $DBConnect); 
echo mysql_error(); 
if (mysql_num_rows($QueryResult)=== 0){ 
    echo "<p style='color:red;'><b>&nbsp;&nbsp;&nbsp;The email address/password " . 
    " combination is not valid.</b></p>\n"; 
    ++$errors; 
    $DisplayForm = TRUE; 
} 
else 
{ 
    $DisplayForm = FALSE; 
} 

} 

} 

if ($DisplayForm) 
{?> 


<form id="form1" name="loginForm" method="post" action="index.php"> 
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0"> 
<tr> 
    <td width="93" bgcolor="#DACFAF"><strong> &nbsp;&nbsp;&nbsp;Username:</strong></td> 
    <td width="149" bgcolor="#DACFAF"><label for="textfield"></label> 
    <input type="text" name="uname" id="textfield" /></td> 
    <td width="76" bgcolor="#DACFAF"><strong>Password:</strong></td> 
    <td width="150" bgcolor="#DACFAF"><label for="textfield2"></label> 
    <input type="password" name="pass" id="pass" /></td> 
    <td width="196" bgcolor="#DACFAF"><input type="image" name="login" src="images/login.jpg" />&nbsp;</td> 
    <td width="68" bgcolor="#DACFAF">&nbsp;</td> 
    <td width="68" bgcolor="#DACFAF"><strong><a href="register.php">Register</a> </strong> </td> 
    </tr> 
</table> 
    </form> 

<?php } 
    else { 
    $Row = mysql_fetch_assoc($QueryResult); 
    $userID = $Row['userid']; 
    $userName = $Row['first_name']. " ". $Row['last_name']; 


    echo "<table width=780px border=0px >"; 
       echo "<tr>"; 
       echo "<td style='color:red;'>"; 
       echo "<b>&nbsp;&nbsp;&nbsp;Welcome back, $userName!</b>"; 
       echo "</td>"; 
       echo"<td align='right'>"; 
       echo "<form method='POST' action=''>"; 
       echo "<input type='submit' name='submit' value='logout'>"; 
       echo "</form>"; 
       echo "</td>"; 
       echo "</tr>"; 
       echo "</table>"; 


    } 


?>&nbsp;</td> 
    </tr> 
</table> 
+0

_ 정확히 당신의 문제는 무엇입니까? _ –

+0

지금 어떤 결과가 나타 납니까? –

+0

세션을 실제로 전달하는 방법을 잘 모르겠습니다. 나는 폼들간에 전달할 수 있지만 다이나믹은 실제로 작동하지 않습니다. – user3479738

답변

0

당신이 $ _SESSION 변수를 설정하는 방법을 알고 가정.

여부

PHP에서 로그에 경우

session_start();를 사용하여 세션을 시작합니다. 모든 점검이 끝난 후에. 변수 이름에 $_SESSION의 이름을 넣으십시오. $의 FIRSTNAME 가정이

$_SESSION['username'] = $firstname.$lastname;

같은

는 사용자의 이름을 가지고 있으며, $의 LASTNAME는 사용자의 성을 가지고있다. THEN

:

당신은 사용자 이름을 표시 할 당신의 PHP 파일의 맨 처음에 session_start();을 넣습니다.

는 모든 PHP 파일의 맨 처음에이 두 가지를 함께 넣어

$userName=$_SESSION['username'];

당신은 이름을 표시합니다. 이제 $userName 변수를 사용하여 이름을 표시 할 수 있습니다.

+0

감사합니다 .. 그것에 작동하고 다시 당신에게 .. 감사합니다. – user3479738

+0

감사합니다. $ _SESSION [ 'username'] = "$ userName"을 추가하여 문제를 해결할 수있었습니다. 내가 전에 가지고 있었던 문제는 내가 페이지의 맨 위에 선언 된 세션에 그것을 추가하고 있다는 것이었다. – user3479738

+0

좋아. 다행이 도울 수있어 :) –

관련 문제