【发布时间】:2015-01-28 09:13:27
【问题描述】:
我试图在用户登录时从数据库中读取用户的 id,并将其保存到变量中以供以后在其他程序中使用。我的用户表是这样的
addressBookUsers
[
userid int(11) PK AUTO_INCREMENT;
firstName;
LastName;
email
]
带有一些虚拟数据
userid username password
1 fred 12ewerefds2
2 al 343ed3fe
这是我使用用户名获取用户 ID 并存储到变量中的代码
<?php
session_start();
include("dbconnect.php");
$con= new dbconnect();
$con->connect();
//create and issue the query
$id = "SELECT userid FROM addressBookUsers WHERE username = '".$_POST["username"]."'";
$userid = mysql_query($id);
while($row = mysql_fetch_array($userid)) {
$me = $row[0]}
$se=$me;
echo($se)
?>
这会返回正确的用户 ID,但是当我尝试在另一个 php 文件中调用 $se 以查看它是否已保存时,我没有得到结果
test.php
<?php
include ("userloginses.php");
echo $se;
?>
我不确定为什么作为 int 的 $se 没有传递给 test.php
有什么帮助吗? 是的,有一些 html 来自不包括在内的东西,但这与手头的问题无关
【问题讨论】:
标签: php sql variables include globals