当我读取行的时候,我想知道如果我想在会话中显示用户名,我应该怎么做。这是我正在检查用户名的代码,如果找到用户名,则返回用户名,但无法显示。
请帮助我或建议我更好的方法。谢谢。错误码:函数
public function Check_login($uname,$pass)
{
//echo $uname;
$check=mysql_query("select name from user where name='$uname' and password='$pass'");
$log=mysql_fetch_row($check);
$abc=mysql_fetch_array($check);
echo $abc['name'];
if($log>0)
{
$_SESSION['login']=1;
echo $_SESSION['name']=$abc['name'];
return $_SESSION['name'];
}
else
{
return false;
}主页:
<?php
session_start();
include('function.php');
$user=new user();
if(!$user->get_session())
{
header("location:index.php");
}
if($_GET['q']=='logout')
{
$user->logout();
header("location:index.php");
}
?>下面是html代码:
<h1>All Information</h1>
Welcome<?php echo $_SESSION['name']; ?></br>
<a href="?q=logout">Logout</a>`enter code here`发布于 2011-11-23 15:02:29
$check=mysql_query("select name from user where name='$uname' and password='$pass'");
session_start();
$abc = array();
if(mysql_num_rows($check) > 0){
$abc=mysql_fetch_array($check);
if(count($abc)>0)
{
$_SESSION['login']=1;
echo $_SESSION['name']=$abc['name'];
return $_SESSION['name'];
}
}
else
{
return false;
}我想这会解决你的问题..使用此代码更改您的代码。
发布于 2011-11-23 15:17:13
对于初学者,我强烈建议使用预准备语句,而不是仅仅在查询中输入用户名/密码。您可以将用户名和密码作为参数绑定到查询,并防止任何类型的sql注入。您还可以将返回的名称绑定到结果,这将使其易于访问。
https://stackoverflow.com/questions/8238325
复制相似问题