0

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

我遇到的问题是在文本框中显示用户的个人资料: student 、fnamelnameprogramlevel 。我使用 MySQL 作为我的后端。genderyear

我的代码是这样的:

<?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代码。

4

2 回答 2

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";
}
?>
于 2012-08-24T04:23:20.533 回答
0

请在会话中添加您的密码

于 2012-08-24T04:20:01.903 回答