How do I echo username in profile page with PHP?

雨燕双飞 提交于 2019-12-08 13:33:46

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!