User Profile tut not working

Post here is you are having problems with any of the tutorials.
roclimb
Posts: 17
Joined: Tue Feb 07, 2012 9:12 pm

User Profile tut not working

Post by roclimb »

Hi,

Ive spent about 3 hours now troubleshooting this tutorial and every time I get a blank page on my local server with absolutely nothing on it.

an someone please help?

Here is my code for ini.inc.php
<?php

session_start();

mysql_connect('localhost','root','mypass');
mysql_select_db('user_profile');


$path = dirname(__file__);

include("{$path}/inc/user.inc.php");



$_SESSION['uid'] = 1;

?>

and for profile.php
<?php

include('core/init.inc.php');

$user_info = fetch_user_info($_GET['uid']);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<htm xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

		<title>Member profile</title>
	</head>
	<body>
	
		<div>
			<?php
			
			if ($user_info === false){
			    echo 'That user does not exist.';
			}else{
				?>
				<h1><?php echo $user_info['firstname']; ?><?php echo $user_info['lastname']; ?></h1>
				<p>Username:<?php echo $user_info['username']; ?> </p>
			    <p>Gender:<?php echo $user_info['gender']; ?> </p>
				<p>Email: <?php echo $user_info['email']; ?></p>
				<p>Location: <?php echo $user_info['location']; ?></p>
			    <p><?php echo $user_info['about']; ?></p>

               <?php
			
			
			
			}
		
		
		?>
		
		
		
		</div>
	
	
	
	</body>
</html>
Last edited by jacek on Wed Feb 08, 2012 4:15 pm, edited 1 time in total.
Reason: code tags...
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: User Profile tut not working

Post by Temor »

Could you post your user.inc.php file? The problem might be in the fetch_user_info function.
roclimb
Posts: 17
Joined: Tue Feb 07, 2012 9:12 pm

Re: User Profile tut not working

Post by roclimb »

<?php

function fetch_users(){

	$result = mysql_query('SELECT `user_id` AS `id`, `user_username` AS `username` FROM `users`');

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

	return $users;
}





?>
Thanks for the reply....I'm really stumped
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: User Profile tut not working

Post by Temor »

well.. there's your problem... you don't have the fetch_user_info function. You need to create that first.

It should have shown an error. Put
error_reporting(E_ALL);
at the top of your init.inc.php to see if it gives you an error.
roclimb
Posts: 17
Joined: Tue Feb 07, 2012 9:12 pm

Re: User Profile tut not working

Post by roclimb »

Thanks again for replying and the assistance but it still did nothing. When I run profile.php I get a completely white/blank page with nothing on it at all.

I added this code
function fetch_user_info($uid){
	$uid = (int)$uid;


	$sql = "SELECT
				`user_username` AS `username`,
				`user_firstname` AS `firstname`,
				`user_lastname` AS `lastname`,
				`user_email` AS `email`,
				`user_about` AS `about`,
				`user_location` AS `location`,
				`user_gender` AS `gender`'
			FROM `users`
			WHERE `user_id` = {$uid}";
			
	$result = mysql_query($sql);			
	
	return mysql_fetch_assoc($result);			
}
But still I get a blank page.
roclimb
Posts: 17
Joined: Tue Feb 07, 2012 9:12 pm

Re: User Profile tut not working

Post by roclimb »

Here is my error
error_reporting(E_ALL); Warning: session_start(): Cannot send session cookie - headers already sent by (output started at -:4) in - on line 7 Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at -:4) in - on line 7 Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in - on line 9 Warning: mysql_connect(): No such file or directory in - on line 9 Warning: mysql_select_db(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in - on line 10 Warning: mysql_select_db(): No such file or directory in - on line 10 Warning: mysql_select_db(): A link to the server could not be established in - on line 10 Warning: include(./inc/user.inc.php): failed to open stream: No such file or directory in - on line 15 Warning: include(): Failed opening './inc/user.inc.php' for inclusion (include_path='.:') in - on line 15
IS the source for this tutorial posted someplace???????

Ive gone over this thing 8 times and can't understand why this wont work.

Rob
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: User Profile tut not working

Post by Temor »

The errors lead me to believe that you have something before the opening <?php tag in your init file and that you're not connecting properly to a MySQL server. Are you sure the MySQL server is running? I started getting similar errors when I turned off MySQL in XAMPP.
roclimb
Posts: 17
Joined: Tue Feb 07, 2012 9:12 pm

Re: User Profile tut not working

Post by roclimb »

thanks again for the help.

I just checked and there is nothing before the opening php tag and the mysql, localhost, tec are working fine too.

is it possible this code is not letting me connect?
#
$path = dirname(__file__);
#
 
#
include("{$path}/inc/user.inc.php");
Is there another way to access the inc/user.inc.php file instead of this?

thanks
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: User Profile tut not working

Post by Temor »

roclimb wrote:thanks again for the help.

I just checked and there is nothing before the opening php tag and the mysql, localhost, tec are working fine too.

is it possible this code is not letting me connect?
#
$path = dirname(__file__);
#
 
#
include("{$path}/inc/user.inc.php");
Is there another way to access the inc/user.inc.php file instead of this?

thanks
That code is working perfectly. Nothing wrong there.

I can't see what would cause your code to fail like this.

Could you post all of your code again?
roclimb
Posts: 17
Joined: Tue Feb 07, 2012 9:12 pm

Re: User Profile tut not working

Post by roclimb »

thanks again for taking the time to help me with this.

Here is my code: ini.inc.php

<?php


session_start();

mysql_connect('localhost','root','mypass');
mysql_select_db('user_profile');


$path = dirname(__file__);

include("{$path}/inc/user.inc.php");



$_SESSION['uid'] = 1;

?>

user.inc.php
<?php

function fetch_users(){

	$result = mysql_query('SELECT `user_id` AS `id`, `user_username` 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_username` AS `username`,
				`user_firstname` AS `firstname`,
				`user_lastname` AS `lastname`,
				`user_email` AS `email`,
				`user_about` AS `about`,
				`user_location` AS `location`,
				`user_gender` AS `gender`'
			FROM `users`
			WHERE `user_id` = {$uid}";
			
	$result = mysql_query($sql);			
	
	return mysql_fetch_assoc($result);			
}
?>

profile.php
<?php

include('core/init.inc.php');

$user_info = fetch_user_info($_GET['uid']);


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<htm xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

		<title>Member profile</title>
	</head>
	<body>
	
		<div>
			<?php
			
			if ($user_info === false){
			    echo 'That user does not exist.';
			}else{
				?>
				<h1><?php echo $user_info['firstname']; ?><?php echo $user_info['lastname']; ?></h1>
				<p>Username:<?php echo $user_info['username']; ?> </p>
			    <p>Gender:<?php echo $user_info['gender']; ?> </p>
				<p>Email: <?php echo $user_info['email']; ?></p>
				<p>Location: <?php echo $user_info['location']; ?></p>
			    <p><?php echo $user_info['about']; ?></p>

               <?php
			
			
			
			}
		
		
		?>
		
		
		
		</div>
	
	
	
	
	
	
	
	</body>
</html>
roclimb
Posts: 17
Joined: Tue Feb 07, 2012 9:12 pm

Re: User Profile tut not working

Post by roclimb »

Ok just figured something out......I did not create the inc folder and that seemed to fix the connect problem, obviously.

Now I am getting a message that says "that user does not exist". So I think my user_info is certainly returning false but I am not sure why as I populated my database. Is there something I should look for to troubleshoot this. I am very, very new to PHP and don't know what code to check errors in my dataase?

It looks like I'm not connecting or finding 'core/init.inc.php'. but why????? My user_list is also showing the two members I entered so that connects for some reason?

Thanks again
Rob
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: User Profile tut not working

Post by Temor »

Oh, okay.

Echo mysql_error(); right under your query but before the return line in fetch_user_info and see if it gives you an error.
roclimb
Posts: 17
Joined: Tue Feb 07, 2012 9:12 pm

Re: User Profile tut not working

Post by roclimb »

Ok, I tried that and I got this:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' FROM `users` WHERE `user_id` = 0' at line 8
That user does not exist.

But I don't know what this means or what syntax I should use, nor where I can reference my manuel.

Do you understand this or what's wrong?
thanks
Rob
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: User Profile tut not working

Post by Temor »

Yes. It means you need to put semiqoutes ( ' ) around {$uid}. The fact that it said user_id = 0 means that the $uid variable is unreadable. Semiqoutes should change that.
  WHERE `user_id` = '{$uid}'";
roclimb
Posts: 17
Joined: Tue Feb 07, 2012 9:12 pm

Re: User Profile tut not working

Post by roclimb »

Ok, I changed that to semi quotes around the var and I still get the same error. I also found an error in the gender line and had a semi quote instead of a comma, I changed that too and still get the same error.

Any ideas????

Really stumped

Rob
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: User Profile tut not working

Post by Temor »

roclimb wrote:Ok, I changed that to semi quotes around the var and I still get the same error. I also found an error in the gender line and had a semi quote instead of a comma, I changed that too and still get the same error.

Any ideas????

Really stumped

Rob
Ah yes.
Remove that comma :) there's not supposed to be anything after that line since it's the "last" line.
roclimb
Posts: 17
Joined: Tue Feb 07, 2012 9:12 pm

Re: User Profile tut not working

Post by roclimb »

I removed the comma and still get the same error message. Why is this TUT not working for me?????
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: User Profile tut not working

Post by Temor »

what does your SQL look like now?
roclimb
Posts: 17
Joined: Tue Feb 07, 2012 9:12 pm

Re: User Profile tut not working

Post by roclimb »

like this:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `users` WHERE `user_id` = '0'' at line 9
That user does not exist.
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: User Profile tut not working

Post by Temor »

that's your error. I was thinking about the actual SQL code.
roclimb
Posts: 17
Joined: Tue Feb 07, 2012 9:12 pm

Re: User Profile tut not working

Post by roclimb »

SQLin user_profile is:
SELECT * 
FROM  `users` 
LIMIT 0 , 30
sql in users:
SELECT  `user_id` ,  `user_username` ,  `user_firstname` ,  `user_lastname` ,  `user_email` ,  `user_about` ,  `user_location` ,  `user_gender` 
FROM  `user_profile`.`users` 
LIMIT 0 , 30
Also since removing that comma after gender I'm getting no error, just says that user does not exist and a blank page other than that....

function fetch_user_info($uid){
	$uid = (int)$uid;


	$sql = "SELECT 
				`user_username` AS `username`,
				`user_firstname` AS `firstname`,
				`user_lastname` AS `lastname`,
				`user_email` AS `email`,
				`user_about` AS `about`,
				`user_location` AS `location`,
				`user_gender` AS `gender`
			FROM `users`
			WHERE `user_id` = '{$uid}'";
			
	$result = mysql_query($sql);			
	
	Echo mysql_error();

	
	return mysql_fetch_assoc($result);			
}
Also under indexes at the very bottom of the sql database it says : PRIMARY BTREE Yes No user_id 2 A
Last edited by jacek on Mon Feb 13, 2012 2:41 pm, edited 1 time in total.
Reason: code tags...
Post Reply