这张照片是我的2个表和Column,我想在表成员中将
“ firstname ”作为$ username,在表帐户中将“ password ”作为我的登录面板的$ password。
这是我的表和列:
我的问题是,如果我加入表格,我不知道该在会话中放入什么内容
if($countacc==1){
$_SESSION['-------this is my problem---------']=$rowacc[0];
$_SESSION['-------this is my problem---------']=$rowacc[1];
$_SESSION['-------this is my problem---------']=$rowacc[2];
$_SESSION['-------this is my problem---------']=$rowacc[3];
header("location: index.php");
}
这是我的完整代码:
<?
session_start();
include "connector.php";
$username=mysql_real_escape_string($_POST['user']);
$password=mysql_real_escape_string($_POST['pass']);
$sqlacc="SELECT * FROM members INNER JOIN accounts ON
account.mem_id =members.mem_id WHERE members.firstname='$username' and accounts.password='$password'";
$resultacc = mysql_query($sqlacc);
$countacc = mysql_num_rows($resultacc);
$rowacc = mysql_fetch_array($resultacc, MYSQL_NUM);
if($countacc==1){
$_SESSION['-------this is my problem---------']=$rowacc[0];
$_SESSION['-------this is my problem---------']=$rowacc[1];
$_SESSION['-------this is my problem---------']=$rowacc[2];
$_SESSION['-------this is my problem---------']=$rowacc[3];
header("location:content/index.php");
}
else{
header("location:login.php");
}
?>
抱歉,如果我的英语语法错误。
你可以这样
session_start();
include "connector.php";
$username = mysql_real_escape_string($_POST['user']);
$password = mysql_real_escape_string($_POST['pass']);
$sqlacc="
SELECT
members.id AS id
members.firstname AS username,
accounts.password AS password
FROM members
INNER JOIN accounts ON account.mem_id =members.mem_id
WHERE members.firstname='$username'
AND accounts.password='$password'";
$resultacc = mysql_query($sqlacc);
$countacc = mysql_num_rows($resultacc);
$rowacc = mysql_fetch_assoc($resultacc);
if($countacc == 1){
$_SESSION['id'] = $rowacc['id'];
$_SESSION['username'] = $rowacc['username'];
$_SESSION['password'] = $rowacc['password'];
header("location:content/index.php");
}
else{
header("location:login.php");
}
在查询中为列提供别名。
代替使用mysql_fetch_array,而使用mysql_fetch_assoc。
您还应该注意,不建议使用mysql函数。您应该使用mysqli函数。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句