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

时间:2013-01-21 03:54:32

标签: 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>

继承我homepage.php的预览

homepage preview

2 个答案:

答案 0 :(得分:1)

您正在使用mysql_query()两次,因此请更改:

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

$info_select = "SELECT..."; //remove mysql_query from here
if ($query_get = mysql_query($info_select)) { //as you have it here
  ...

注意:不推荐使用mysql_ *,而是使用MySQLiPDO_MySQL

答案 1 :(得分:0)

您没有将studid传递到getuserinfo($info)函数中,而在您的查询中,您已使用$voter将您在外部定义到函数中,请使用global if你想从外部访问函数。

$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