Problems with User Profile

Post here is you are having problems with any of the tutorials.
Post Reply
matzpenner08
Posts: 5
Joined: Sun May 08, 2011 1:54 pm

Problems with User Profile

Post by matzpenner08 »

Hey,
i've send you a massage in youtube and now i'm here...so
if i open profile.php with my browser there are these two warnings/notices:

Notice: Undefined index: uid in C:\xampp\htdocs\PHP User Profile\profile.php on line 5

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\PHP User Profile\user.php on line 32

i dont know what's wrong...maybe you can send me your scripts and i take a look and find the mistake...
my e-mail address is : matthiashaselmaier@hotmail.de

thx

the code:
<?php

include('init.php');

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

?>
<html>
	<head>
    	<meta http-equiv="content-type" content="text/html"; charset="utf-8" />
        <title><?php echo $user_info['username']; ?>'s Profile</title>
    </head>
    <body>
    	<div>
        	<?php
			
			if ($user_info === false){
				echo 'That user does net 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'] == 1) ? 'Male' : 'Female'; ?></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 matzpenner08 on Sun May 08, 2011 2:07 pm, edited 1 time in total.
Tino
Posts: 360
Joined: Thu May 05, 2011 8:55 pm
Location: The Netherlands

Re: Problems with User Profile

Post by Tino »

What's your code?
Please check out my CodeCanyon items.
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: Problems with User Profile

Post by Temor »

Post your code here using the syntax php tags and we'll have a look at it :)
Tino
Posts: 360
Joined: Thu May 05, 2011 8:55 pm
Location: The Netherlands

Re: Problems with User Profile

Post by Tino »

So what does your URL like? It probably doesn't have uid anywhere in it.
Please check out my CodeCanyon items.
matzpenner08
Posts: 5
Joined: Sun May 08, 2011 1:54 pm

Re: Problems with User Profile

Post by matzpenner08 »

Tino wrote:So what does your URL like? It probably doesn't have uid anywhere in it.
if i type in :http://localhost/Php%20User%20Profile/profile.php?uid=1
there is the warning : "Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\PHP User Profile\user.php on line 32"
again
Tino
Posts: 360
Joined: Thu May 05, 2011 8:55 pm
Location: The Netherlands

Re: Problems with User Profile

Post by Tino »

What's the code of user.php?
Please check out my CodeCanyon items.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Problems with User Profile

Post by jacek »

You probably have a error in the SQL in the fetch_user_info() function.

if you add
echo mysql_error();
after it it will tell you what's wrong.
Image
matzpenner08
Posts: 5
Joined: Sun May 08, 2011 1:54 pm

Re: Problems with User Profile

Post by matzpenner08 »

Tino wrote:What's the code of user.php?
<?php

//fetches all of ths users from the table
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;	
}

//fetches profile information for the given user.
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);
}

//updates the current users profile info.
function set_profil_info($email, $about, $location){
	$email 		= mysql_real_escape_string(htmlentities($email));
	$about 		= mysql_real_escape_string(nl2br(htmlentities($about)));
	$location   = mysql_real_escape_string($location);
	
	$sql = "UPDATE 'users' SET
				   'user_email' = '{$email}',
				   'user_about' = '{$about}',
				   'user_location' = '{$location}'
			WHERE 'user_id' = {$_SESSION['uid']}";
	
	mysql_query($sql);
}

?>
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Problems with User Profile

Post by jacek »

Looks like you have the wrong type of quotes around your column and table names, columns should have ` around them.

EDIT: also moved to tutorial help as this is related to a tutorial ;)
Image
Tino
Posts: 360
Joined: Thu May 05, 2011 8:55 pm
Location: The Netherlands

Re: Problems with User Profile

Post by Tino »

In the query, you want all those quotes to be backticks instead.

edit: got beaten to it.
Please check out my CodeCanyon items.
matzpenner08
Posts: 5
Joined: Sun May 08, 2011 1:54 pm

Re: Problems with User Profile

Post by matzpenner08 »

jacek wrote:Looks like you have the wrong type of quotes around your column and table names, columns should have ` around them.

EDIT: also moved to tutorial help as this is related to a tutorial ;)
you mean like this over the a : à!?
i'm not sure if this is the right type
Tino
Posts: 360
Joined: Thu May 05, 2011 8:55 pm
Location: The Netherlands

Re: Problems with User Profile

Post by Tino »

Yes, exactly that one ;)

The one below the Esc key.
Please check out my CodeCanyon items.
matzpenner08
Posts: 5
Joined: Sun May 08, 2011 1:54 pm

Re: Problems with User Profile

Post by matzpenner08 »

Tino wrote:Yes, exactly that one ;)

The one below the Esc key.
well i'm from germany i got an other keyboard...:D
but thx i'll try it!
Tino
Posts: 360
Joined: Thu May 05, 2011 8:55 pm
Location: The Netherlands

Re: Problems with User Profile

Post by Tino »

Ah, okay. At least you know which key you should have.
Please check out my CodeCanyon items.
Post Reply