0

here is my code...

loginscript.php
<?php
ini_set('display_errors', true);
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="seelsdb"; // Database name 
$tbl_name="tblteacher"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form 
$uname=$_POST['uname']; 
$pword=$_POST['pword']; 
// To protect MySQL injection (more detail about MySQL injection)
$uname = stripslashes($uname);
$pword = stripslashes($pword);
$uname = mysql_real_escape_string($uname);
$pword = mysql_real_escape_string($pword);
$sql="SELECT * FROM $tbl_name WHERE teacherEmail='$uname' and teacherPass='$pword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){

// Register $myusername, $mypassword and redirect to file "login_success.php"
session_start();
$_SESSION['loginp']=$pword;
$_SESSION['login']=$uname;
header("location:schedule.php");
}
else {
echo "Wrong Username or Password";
}

?>

and here is a snippet of schedule.php

<?php
session_start();
$uname=$_SESSION['login'];
echo $uname;
?>
<!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=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body class="body">
<table class="maintable">
<tr valign="top">
<td align="center">
<img src="images/banner.jpg"   />
</td>
</tr>

<tr>
<td>
<!-- this part is for the menu area -->
</td>
</tr>
</table>
<table>
<tr valign="top">
<td width="20%">
<!-- this part is for the login part -->
<table>
<tr>
<td>
<!-- i want to display $_SESSION['login'] here -->
WELCOME! $uname 
</td>
</tr>

</table>

now, how can i get the value of $_SESSION['login'] from loginscript.php and display it in one of the table cells in schedule.php???

i am getting an error that says Notice: Undefined index: login

4

3 回答 3

0

利用;

WELCOME! <?php echo $uname; ?>

反而

于 2012-08-25T09:43:53.020 回答
0

simple, you should print the variable with PHP

WELCOME! <?php echo $uname; ?>

on the other hand, in first file (loginscript.php) you should add session_start() right before <?php because you have ini_set('display_errors', true); and that will break your session.

于 2012-08-25T09:10:41.583 回答
0

首先,您应该在 loginscript.php 中发送标头之前启动会话。其次,您应该像 . 在源代码session_start();中,您应该在 loginscript.php 中添加一行(这应该是第一行),并且在 HTML 代码中打印用户名时,您应该而不是echo hello $uname编写<? echo"hello $uname"; ?>

于 2012-08-25T09:11:20.233 回答