问题
So I want to echo the users' "username" on their profile. It's not working when I user this piece of code. why? Help please i echo'ed this on my page <?php echo "<td>" . $row['username'] . "</td>";?>
but didn't work
<?php
if (!session_id()) session_start();
if (!$_SESSION['logon']){
header("Location:login.php");
die();
}
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$result = mysql_query("SELECT * FROM `users` where username='$username'");
while($row = mysql_fetch_array($result))
$username = $row['username'];
?>
回答1:
Try <?php echo $username; ?>
回答2:
Try mysql_fetch_assoc
function without while
loop:
$row = mysql_fetch_assoc($result);
<?php echo "<td>" . $row['username']; . "</td>"; ?>
来源:https://stackoverflow.com/questions/24584165/how-do-i-echo-username-in-profile-page-with-php