0

これが私のコードです...

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";
}

?>

これが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>

ここで、loginscript.phpから$ _SESSION ['login']の値を取得し、schedule.phpのテーブルセルの1つに表示するにはどうすればよいですか?

注意:未定義のインデックス:ログインというエラーが表示されます

4

3 に答える 3

0

単純です。変数を次のように出力する必要があります。PHP

WELCOME! <?php echo $uname; ?>

一方、最初のファイル( )では、セッションが中断されるため、直前にloginscript.php追加する必要があります。session_start()<?phpini_set('display_errors', true);

于 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 に答える
0

使用する;

WELCOME! <?php echo $uname; ?>

代わりは

于 2012-08-25T09:43:53.020 に答える