显示用户配置文件中记录的当前值

时间:2012-08-24 04:15:14

标签: php mysql

我一直在研究学生注册的代码。我完成了登录的编码。

我遇到的问题是显示用户的个人资料:文本框中的学生fnamelnameprogramgenderyear级别。我正在使用MySQL作为我的后端。

我的代码是这样的:

<?php 

// connects to the database
$mysqli = new mysqli("localhost", "root", "");

$query = 'SELECT fname, lname, program, gender, year FROM students WHERE fname =     '.$_SESSION['myusername'];
$mysqli->query($query);


echo "<div align=\"center\">";
echo "<br />Your <b><i>Profile</i></b> is as follows:<br />";
echo "<b>First name:</b> ". $_POST['fname'];
echo "<br /><b>Last name:</b> ".$_POST['lname'];
echo "<br /><b>Program:</b> ".$_POST['program'];
echo "<br /><b>Year:</b> ".$_POST['year'];
echo "<br /><b>Gender:</b> ".$_POST['gender'];
echo "</div>";
?>

这是我mainstudent.phpchecklogin.php的代码。

2 个答案:

答案 0 :(得分:2)

你走了:

<?php 
session_start();

// connects to the database
$mysqli = new mysqli("localhost", "root", "");

$query = "SELECT fname, lname, program, gender, year FROM students WHERE fname = '".$_SESSION['myusername']."'";
if($result = $mysqli->query($query))
{
    while($row = $result->fetch_assoc())
    {
        echo "<div align=\"center\">";
        echo "<br />Your <b><i>Profile</i></b> is as follows:<br />";
        echo "<b>First name:</b> ". $row['fname'];
        echo "<br /><b>Last name:</b> ".$row['lname'];
        echo "<br /><b>Program:</b> ".$row['program'];
        echo "<br /><b>Year:</b> ".$row['year'];
        echo "<br /><b>Gender:</b> ".$row['gender'];
        echo "</div>"   
    }
    $result->free();
}
else
{
    echo "No results found";
}
?>

答案 1 :(得分:0)

请在会话中添加密码