Php 显示用户配置文件信息
我在单击用户配置文件时显示用户配置文件信息时遇到问题。登录时显示的数据是我自己的,因此不会切换。我找不到问题所在,想知道我可能哪里出了问题 因此,这些信息应该显示在profile.php上Php 显示用户配置文件信息,php,Php,我在单击用户配置文件时显示用户配置文件信息时遇到问题。登录时显示的数据是我自己的,因此不会切换。我找不到问题所在,想知道我可能哪里出了问题 因此,这些信息应该显示在profile.php上 if (isset($_GET['username']) === true && empty ($_GET['username']) === false) { $username = $_GET['username']; if (user_exists($username)
if (isset($_GET['username']) === true && empty ($_GET['username']) === false) {
$username = $_GET['username'];
if (user_exists($username) === true) {
$user_id = user_id_from_username($username);
$profile_data = user_data($user_id, 'first_name', 'last_name', 'email');
?>
<h1><?php echo $profile_data['first_name']; ?> profile</h1>
<p><?php echo $profile_data['email'] ?></p>
<?php
} else {
echo 'Sorry, that user does not exist';
}
} else {
header('Location: index.php');
exit();
}
Im使用.htaccess文件初始化虚荣URL
RewriteEngine On
RewriteCon %{REQUEST_FILENAME} !-f
RewriteCon %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /profile.php?username=$1
所以我的URL看起来像这样
以下是用户_数据的函数
function user_data($user_id) {
$data = array();
$user_id = (int)$unser_id;
$func_num_args = func_num_args();
$func_get_args = func_get_args();
if ($func_num_args > 1){
unset($func_get_args[0]);
$fields = '`' . implode('`, `', $func_get_args) . '`';
$data = mysql_fetch_assoc(mysql_query("SELECT $fields FROM `users` WHERE 'user_id' = $user_id"));
return $data;
}
}
它的工作原理是更改myname,但不将配置文件页面上的用户数据切换到其他用户数据
根据请求:用户存在()函数
function user_exists($username) {
$username = sanitize($username);
$query = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'");
return (mysql_result($query, 0) == 1) ? true : false;
}
试试这个
function user_data($user_id, $fields = '*') {
// type cast to int
$user_id = (int) $user_id;
// if an array is passed, we implode the array to get fields,
// otherwise we return all rows
if (is_array($fields))
{
$fields = implode('`, `', $fields) . '`';
}
//build query, with LIMIT 1 , I assume username is unique
$qry = "SELECT {$fields} FROM `users` WHERE 'user_id' = {$user_id} LIMIT 1";
$sql = mysql_query($qry);
$result = mysql_fetch_assoc($sql);
// if we have a result, return it, otherwise return false
return (mysql_num_rows($sql) == 1) ? $result : false ;
}
使用:
$profile_data = user_data($user_id, array('user_id', 'username', 'password', 'first_name', 'last_name', 'email', 'type', 'profile'));
或
听起来问题可能出在用户名()中的用户id()或用户数据()中。因为你没有发布这些,我们无法提供帮助。我添加了用户数据功能等待,你是说登录时显示信息是错误的?我想我不明白的是,我想这应该是正确的行为echo
user\u id\u from\u username($username)
。现在,将您的错误报告设置为调试合理的级别。另外,对于新开发,如果可以的话,可以使用PDO
或mysqli.*
函数。要使用的部分。。。这是在profile.php上进行的吗?我要替换什么?你有skype吗?
$profile_data = user_data($user_id, array('user_id', 'username', 'password', 'first_name', 'last_name', 'email', 'type', 'profile'));
$fields = array(
'user_id',
'username',
'password',
'first_name',
'last_name',
'email',
'type',
'profile'
);
$profile_data = user_data($user_id, $fields);