Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何根据学生id获取用户数据或信息?_Php - Fatal编程技术网

Php 如何根据学生id获取用户数据或信息?

Php 如何根据学生id获取用户数据或信息?,php,Php,流程是这样的,登录(login.php)->更改密码(changepass.php),每个用户都必须更改密码->在主页(homepage.php)上重定向,用户可以查看他/她的帐户详细信息…我在主页上想要的是,根据用户的信息或完整的用户名问候用户,但当我回显会话时,我只能显示用户的学生id。这是我的homepage.php的代码 <?php session_start(); ?> <?php require('connect/connect.php'

流程是这样的,登录(login.php)->更改密码(changepass.php),每个用户都必须更改密码->在主页(homepage.php)上重定向,用户可以查看他/她的帐户详细信息…我在主页上想要的是,根据用户的信息或完整的用户名问候用户,但当我回显会话时,我只能显示用户的学生id。这是我的homepage.php的代码

       <?php session_start(); ?>
       <?php require('connect/connect.php'); ?>
       <!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=utf-8" />
      <title>Home Page</title>


    <link href="mm_spa.css" rel="stylesheet" type="text/css" />
      </head>

         <body class="oneColElsCtrHdr">

      <td width="487" valign="top">

    <?php
    // this is the session id where i could only get from the user(student id)
echo $_SESSION['username'];
$voter = $_SESSION['username'];
function getuserinfo($info){

$info_select = mysql_query ("SELECT `$info` FROM new_reg_student WHERE studid='$voter'");

     //this is my line 116 which i got an error saying 
     //Warning: mysql_query() expects parameter 1 to be string, 
     //resource given in C:\xampp\htdocs\project\homepage.php on line 116
if ($query_get = mysql_query($info_select)) { 

if ($result = mysql_result($query_get, 0, $info)) {
return $result;
}
}

}
$fname = getuserinfo('fname');
$lname = getuserinfo('lname');
echo 'hello '. $fname .' '.$lname.'';

   ?>

  </td>
    <div id="footer">
   <p>Footer</p>
    <!-- end #footer --></div>
  <!-- end #container --></div>
   </body>
  </html>

主页
页脚

这是我的主页的预览

       <?php session_start(); ?>
       <?php require('connect/connect.php'); ?>
       <!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=utf-8" />
      <title>Home Page</title>


    <link href="mm_spa.css" rel="stylesheet" type="text/css" />
      </head>

         <body class="oneColElsCtrHdr">

      <td width="487" valign="top">

    <?php
    // this is the session id where i could only get from the user(student id)
echo $_SESSION['username'];
$voter = $_SESSION['username'];
function getuserinfo($info){

$info_select = mysql_query ("SELECT `$info` FROM new_reg_student WHERE studid='$voter'");

     //this is my line 116 which i got an error saying 
     //Warning: mysql_query() expects parameter 1 to be string, 
     //resource given in C:\xampp\htdocs\project\homepage.php on line 116
if ($query_get = mysql_query($info_select)) { 

if ($result = mysql_result($query_get, 0, $info)) {
return $result;
}
}

}
$fname = getuserinfo('fname');
$lname = getuserinfo('lname');
echo 'hello '. $fname .' '.$lname.'';

   ?>

  </td>
    <div id="footer">
   <p>Footer</p>
    <!-- end #footer --></div>
  <!-- end #container --></div>
   </body>
  </html>
您使用了两次,因此请更改:

$info_select = mysql_query ("SELECT ... ");


注意:mysql_*已被弃用,请使用或

您没有将
studid
传递到您的
getuserinfo($info)
函数中,并且在查询中使用了在函数外部定义的
$voter
,如果要从函数外部访问变量,请使用
global

$voter = $_SESSION['username'];

function getuserinfo($info){

// Call the Student ID
global $voter;

$info_select = "SELECT $info FROM new_reg_student 
                    WHERE studid='".mysql_real_escape_string($voter)."'";

if ($query_get = mysql_query($info_select)) { 
    ......
}
} // Function Close

也感谢您的回复,现在我可以问候我的用户了…=)