Page 1 of 1

Re: updating feilds/display info

Posted: Tue May 31, 2011 8:39 pm
by jacek
Well you have
$user_info = fetch_user_info($_SESSION['uid']);
In the first code twice, so one of those needs to be removed (the first one)

And can you see what the fetch_user_info function is returning by adding
var_dump($user_info);
on the page somewhere and seeing what the output is.

If you get bool(false) it means that the query is either failing for some reason (and you have error_reporting off) or it is returning 0 rows, in which case you should check the value of the session variable to make sure it is what you expect.

that's how I would debug this anyway ;)

Re: updating feilds/display info

Posted: Wed Jun 01, 2011 8:28 am
by jacek
uhshosting wrote:its returning as bool false and the info is returning 0 for all rows. and i tried mysql error() and also did not find anything.
how do i find the error i re looked everything over and didnt see any problems and tested a few things and nothing changed
If you add
var_dump($_SESSION['uid']);
Do you get the output that you expect ?

Also do you have E_NOTICE level errors shown, because they often highlight typos in variable names that could cause this problem. you can enable them by adding
error_reporting(E_ALL);
to the top of the page.

Re: updating feilds/display info

Posted: Thu Jun 02, 2011 3:15 pm
by jacek
do you have session_start() in your init file ?

Re: updating feilds/display info

Posted: Thu Jun 02, 2011 4:03 pm
by jacek
Is that the ../admin/profiles/core/init.inc.php file ?

if so, try moving the error reporting line above the include to see if php is giving an error for the session_start

Re: updating feilds/display info

Posted: Thu Jun 02, 2011 5:48 pm
by jacek
the idea is that you use the same init file ;)

The error is caused because php needs to send a header to set the session cookie, and headers have to come before output just because that's how HTTP works (headers first)

PHP is telling you where the output causing the error comes from /home/doe64/public_html/account/user/index.php:12 the 12 at the end means line 12. So you need to include the init file before this point, in fact before any output.

Re: updating feilds/display info

Posted: Thu Jun 02, 2011 6:20 pm
by jacek
uhshosting wrote:this makes no sence i have 3 init files 1 for login, 1 for profiles, 1 for dynamic pages i tried using 1 and nothing is working
The idea of the init file is that it set up all the things you need to use al all of the pages, if you have one for each page you may as well just have the code on the page its self.

As you are so vague abotu the problem "nothing is working" I can't really help with that, but it sounds like a separate issue so should go in a new topic ;)

Re: updating feilds/display info

Posted: Thu Jun 02, 2011 7:39 pm
by jacek
Am I right to say that this is one of the page files form my template system ? If so the init file should be included by the index.php page not by each individual page file.

Re: updating feilds/display info

Posted: Thu Jun 02, 2011 7:51 pm
by jacek
uhshosting wrote:ok that makes scene and works but still the fatal error
then it doesn't work :lol:

Are you including the library file ?

Re: updating feilds/display info

Posted: Thu Jun 02, 2011 8:14 pm
by jacek
uhshosting wrote:the library file?
where you define the fetch_users() function.

Re: updating feilds/display info

Posted: Thu Jun 02, 2011 9:04 pm
by jacek
uhshosting wrote:the user inc file?
And is that still being included ?

Re: updating feilds/display info

Posted: Fri Jun 03, 2011 2:35 am
by Temor
uhshosting wrote:i have a fatal error:
Fatal error: Cannot redeclare fetch_users() (previously declared in /home/doe64/public_html/account/admin/profiles/core/inc/user.inc.php:4) in /home/doe64/public_html/account/admin/profiles/core/inc/user.inc.php on line 13

i know why its causing it but im not sure how to fix it.
<?php

function fetch_users(){
	$result = mysql_query('SELECT `user_id` AS `id`, `user_name` AS `username` FROM `users`');	

	$users = array();
	
	while (($row = mysql_fetch_assoc($result)) !== false){
		
	$users[] = $row;	
	}
	return $users;
}

function fetch_user_info($uid){
	$uid = (int)$uid;
	
	$sql = "SELECT
`user_name` AS `username`,
`user_phone` AS `phone`,
`user_firstname` AS `firstname`,
`user_lastname` AS `lastname`,
`user_gender` AS `gender`,
`user_state` AS `state`,
`user_city` AS `city`,
`user_zip` AS `zip`,
`user_street` AS `street`
FROM `users`
WHERE `user_id` = {$uid}";
	$result = mysql_query($sql);
	
	return mysql_fetch_assoc($result);

}

function set_profile_info($username, $state){
	$username = mysql_real_escape_string(htmlentities($username));	
	$state = mysql_escape_string(htmlentities($state));
	
	$sql = "UPDATE `users` SET
				`user_name` = '{$username}',
				`user_phone` = {$phone}',
				`user_firstname` = {$firstname}',
				`user_lastname` = {$lastname}',
				`user_state` = {$state}',
				`user_city` = {$city}',
				`user_zip` = {$zip}',
				`user_street` = {$street}',
			WHERE `user_id` = {$_SESSION['uid']}";
			
			mysql_query($sql);
}
?>[/php]
[php]<?php
//checks if the given username is in the table
function user_exists($user){
	$user = mysql_real_escape_string($user);
	
	$total = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `user_name` = '{$user}'");
	
	
	return (mysql_result($total, 0) == '1') ? true : false;
	
}
echo mysql_error();

// checks if the given username and passwword is valid
function valid_credentials($user, $pass){
	$user = mysql_real_escape_string($user);
	$pass = sha1($pass);
	
	$total = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `user_name` = '{$user}' AND `user_password` = '{$pass}'");
	
	return (mysql_result($total, 0) == '1') ? true : false;
}

// adds user to the database
function add_user($user, $pass){
	$user = mysql_real_escape_string(htmlentities($user));
	$pass = sha1($pass);
	
	mysql_query("INSERT INTO `users` (`user_name`, `user_password`) VALUES ('{$user}', '{$pass}')");
	
}

?>
You're calling your user.inc.php twice somewhere.

Re: updating feilds/display info

Posted: Fri Jun 03, 2011 11:20 am
by jacek
uhshosting wrote:that may have been the problem. but when i do include it it cant find it which is odd because heres the error:
Warning: include(/admin/profiles/core/inc/user.inc.php) [function.include]: failed to open stream: No such file or directory in /home/doe64/public_html/account/init.inc.php on line 7
When you start an include path with / it means the root of the drive on windows this would be C: for example. so remove the first /
uhshosting wrote:i have a fatal error:
Fatal error: Cannot redeclare fetch_users() (previously declared in /home/doe64/public_html/account/admin/profiles/core/inc/user.inc.php:4) in /home/doe64/public_html/account/admin/profiles/core/inc/user.inc.php on line 13
As Temor said, you are including the users.inc.php file more than once.