Jump to content

Problem pulling data from database..


saamde

Recommended Posts

Hello, i'v been following a tut on how to make a register and login system and iv hit a brick wall... It won't display data..

 

This is my users.php

<?php
function user_data($user_id) {
	$data = array();
	$user_id = (int)$user_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;
	}
}

function logged_in() {
	return (isset($_SESSION['user_id'])) ? true : false;
}

function user_exists($username) {
$username = sanitize ($username);
(mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'"), 0) == 1) ? true : false;
}

function user_active($username) {
$username = sanitize ($username);
return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `active` = 1"), 0) == 1) ? true : false;
}

function user_id_from_username($username) {
$username = sanitize($username);
return mysql_result(mysql_query("SELECT `user_id` FROM `users` WHERE `username` = '$username'"), 0, 'user_id');
}

function login($username, $password) {
$user_id = user_id_from_username($username);

$username = sanitize($username);
$password = md5($password);

return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `password` = '$password'"), 0) ==1) ? '$user_id' : false;
}
?>

and iv used this(see code) to get the user first name,

Hello, <?php echo $user_data['first_name']; ?>!

buts its showing like this...(see image)

 

fI6YKYS.png

 

 

Help anyone?

 

 

Thanks, Sam

 

If you need to see some other code files, let me know and ill post.

Link to comment
https://forums.phpfreaks.com/topic/283160-problem-pulling-data-from-database/
Share on other sites

And what's the code that sets $user_data?

 

 

Also, user_data() won't return anything if you don't pass it the fields you want returned. If a function returns a value then it should always return a value. Maybe you can assume a default of getting all the fields?

 

 

Hello, i'v been following a tut on how to make a register and login system 

What is this tutorial?

 

I am sensing daja vu http://forums.phpfreaks.com/topic/282635-cannot-view-the-fields-unless-i-state-select-all-but-it-still-does-not-work/

 

Is this a repost?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.