将数据从php脚本文件传输到另一个脚本文件

将数据从php脚本文件传输到另一个脚本文件,php,phpmyadmin,Php,Phpmyadmin,这是我的密码 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 // C

这是我的密码

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

?>
loginscript.php
下面是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>

无标题文件
欢迎光临$uname
现在,我如何从loginscript.php获取$_SESSION['login']的值并将其显示在schedule.php中的一个表单元格中


我收到一个错误,上面写着注意:未定义索引:login

简单,您应该使用
PHP

WELCOME! <?php echo $uname; ?>
欢迎!

另一方面,在第一个文件(
loginscript.php
)中,您应该在
之前添加
session\u start()
。在第一个文件中,您应该在loginscript.php中发送头之前启动session。第二,您应该像打印登录。在源代码中,您应该添加
session_start()行到loginscript.php(这应该是第一行),在HTML代码中打印用户名时,应该使用
echo hello$uname
write
Use

WELCOME! <?php echo $uname; ?>
欢迎!

相反

@jogesh\p你读了他的问题和代码了吗?请阅读第二个代码段的最后6行。先生,两个脚本都在不同的文件中,我删除了schedule.php中的第一个echo,现在它仍然给出一个错误,注意:未定义的索引:登录到第4行,即$uname=$\u SESSION['login'];其实一点也不好笑。“程序员”不知道如何使用echo,嗯,我可以澄清一下你的答案吗?先生,在阅读第一段代码之前,我应该添加session_start是什么意思?第二段,我添加了session_start();或者你的意思是它应该放在@PatrickNarcelles之后,请将你编辑的代码发布到pastebin,或者在这里查看。先生,我更改了schedule.php的第一部分,但我还没有更改loginscript。php@PatrickNarcelles您是否添加了
session_start()loginscript.php文件中