Problems with User Profile
-
- Posts: 5
- Joined: Sun May 08, 2011 1:54 pm
Problems with User Profile
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]
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]
Last edited by matzpenner08 on Sun May 08, 2011 2:07 pm, edited 1 time in total.
Re: Problems with User Profile
Post your code here using the syntax php tags and we'll have a look at it
Re: Problems with User Profile
So what does your URL like? It probably doesn't have uid anywhere in it.
Please check out my CodeCanyon items.
-
- Posts: 5
- Joined: Sun May 08, 2011 1:54 pm
Re: Problems with User Profile
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
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.
if you add
[syntax=php]echo mysql_error();[/syntax]
after it it will tell you what's wrong.
-
- Posts: 5
- Joined: Sun May 08, 2011 1:54 pm
Re: Problems with User Profile
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
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
EDIT: also moved to tutorial help as this is related to a tutorial
Re: Problems with User Profile
In the query, you want all those quotes to be backticks instead.
edit: got beaten to it.
edit: got beaten to it.
Please check out my CodeCanyon items.
-
- Posts: 5
- Joined: Sun May 08, 2011 1:54 pm
Re: Problems with User Profile
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
Yes, exactly that one
The one below the Esc key.
The one below the Esc key.
Please check out my CodeCanyon items.
-
- Posts: 5
- Joined: Sun May 08, 2011 1:54 pm
Re: Problems with User Profile
Tino wrote:Yes, exactly that one
The one below the Esc key.
well i'm from germany i got an other keyboard...
but thx i'll try it!
Re: Problems with User Profile
Ah, okay. At least you know which key you should have.
Please check out my CodeCanyon items.