如何使用PHP在配置文件页面中回显用户名? [英] How do I echo username in profile page with PHP?
本文介绍了如何使用PHP在配置文件页面中回显用户名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<?php echo< td> 。 $ row ['username']。 < / td>;?>
但无效 < 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'];
?>
解决方案
尝试 mysql_fetch_assoc $
while循环:
$ row = mysql_fetch_assoc ($结果);
<?php echo< td> 。 $行[用户名]; 。 < / TD> 中; ?>
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'];
?>
解决方案
Try mysql_fetch_assoc
function without while
loop:
$row = mysql_fetch_assoc($result);
<?php echo "<td>" . $row['username']; . "</td>"; ?>
这篇关于如何使用PHP在配置文件页面中回显用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文