本文介绍了如何使用PHP在配置文件页面中回显用户名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我想在用户的个人资料上回复用户的用户名。当我使用这段代码时,它不起作用。为什么?请帮我在我的页面上回显此内容尝试 mysql_fetch_assoc $ while循环:
$ row = mysql_fetch_assoc ($结果);
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在配置文件页面中回显用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!