2013-01-21 12 views
0

流程如下,login(login.php) - >更改密碼(changepass.php),其中每個用戶必須更改密碼 - >在主頁(homepage.php)上重定向,用戶可以在其中查看他/她的accnt細節....我想在我的主頁上,是根據其信息或studentid與其完整的名稱迎接用戶,但只有我可以顯示的是用戶的學生ID,因爲我回聲會話。我的繼承人爲我homepage.php我如何根據學生ID獲取用戶數據或信息?

 <?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 preview

回答

1

您使用mysql_query()兩次我homepage.php的預覽代碼,因此改變:

$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

+0

thnks很多爵士....它真的幫助我 –

+0

歡迎您... :) –

0

你沒有通過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 
+0

也感謝你的回答,現在我可以迎接我的用戶... =) –

相關問題