Page 1 of 1

Problems with User Profile

Posted: Sun May 08, 2011 2:03 pm
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:
[syntax=php]<?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>[/syntax]

Re: Problems with User Profile

Posted: Sun May 08, 2011 2:05 pm
by Tino
What's your code?

Re: Problems with User Profile

Posted: Sun May 08, 2011 2:06 pm
by Temor
Post your code here using the syntax php tags and we'll have a look at it :)

Re: Problems with User Profile

Posted: Sun May 08, 2011 2:08 pm
by Tino
So what does your URL like? It probably doesn't have uid anywhere in it.

Re: Problems with User Profile

Posted: Sun May 08, 2011 2:11 pm
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

Re: Problems with User Profile

Posted: Sun May 08, 2011 2:12 pm
by Tino
What's the code of user.php?

Re: Problems with User Profile

Posted: Sun May 08, 2011 2:13 pm
by jacek
You probably have a error in the SQL in the fetch_user_info() function.

if you add

[syntax=php]echo mysql_error();[/syntax]

after it it will tell you what's wrong.

Re: Problems with User Profile

Posted: Sun May 08, 2011 2:13 pm
by matzpenner08
Tino wrote:What's the code of user.php?

[syntax=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);
}

?>[/syntax]

Re: Problems with User Profile

Posted: Sun May 08, 2011 2:15 pm
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 ;)

Re: Problems with User Profile

Posted: Sun May 08, 2011 2:15 pm
by Tino
In the query, you want all those quotes to be backticks instead.

edit: got beaten to it.

Re: Problems with User Profile

Posted: Sun May 08, 2011 2:17 pm
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

Re: Problems with User Profile

Posted: Sun May 08, 2011 2:18 pm
by Tino
Yes, exactly that one ;)

The one below the Esc key.

Re: Problems with User Profile

Posted: Sun May 08, 2011 2:19 pm
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!

Re: Problems with User Profile

Posted: Sun May 08, 2011 2:20 pm
by Tino
Ah, okay. At least you know which key you should have.