这里的代码工作得很好。我想要做的就是传递已存储在$ 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> 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> 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" /> </td>
<td width="68" bgcolor="#DACFAF"> </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> 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>";
}
?> </td>
</tr>
</table>
_什么是你的问题?_ –
你现在得到什么结果? –
我不确定如何真正通过会话。我可以在表单之间传递,但动态并不真正起作用。 – user3479738