Page 1 of 1

User Profile tutorial

Posted: Sat Oct 08, 2011 3:59 pm
by wignall6
Hello,

I am implementing the user profile system into your login system. On the edit profile page it isn't grabbing the users information. I have changed the session parts to the session in the login but it still doesn't get the information.

This is my edit_profile.php -
[syntax=php]<?php

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

if (isset($_POST['email'], $_POST['location'], $_POST['about'])) {
$errors = array();

if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) {
$errors[] = 'The email address you entered is not valid.';
}

if (preg_match('#^[1-z0-9 ]+$#i', $_POST['location']) === 0) {
$errors[] = 'Your location must only contain a-z, 0-9 and spaces.';
}

if (empty($errors)) {
set_profile_info($_POST['email'], $_POST['about'], $_POST['location']);
}

$user_info = array(
'email' => htmlentities($_POST['email']),
'about' => htmlentities($_POST['about']),
'location' => htmlentities($_POST['location'])
);
} else {
$user_info = fetch_user_info($_SESSION['username']);
}

$user_info = fetch_user_info($_SESSION['username']);

?>[/syntax]

and this is my fetch_user_info function -
[syntax=php]// Fetches profile information for the given user.
function fetch_user_info($uid) {
$uid = (int)$uid;

$sql = "SELECT
`user_name` AS `username`,
`first_name` AS `firstname`,
`last_name` 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);
}[/syntax]

The fetch_user_info shouldn't matter anyway, but in the PHP of edit_profile.php it sets the session to 'username' and that's the session set in my login.php.

Re: User Profile tutorial

Posted: Sat Oct 08, 2011 9:34 pm
by jacek
You are passing the username to a functions which expects a user ID.

Re: User Profile tutorial

Posted: Sun Oct 09, 2011 9:19 pm
by wignall6
Yeah, how would I make it so the page will get the userid to display the right information.

Re: User Profile tutorial

Posted: Mon Oct 10, 2011 7:29 pm
by jacek
Probably best to store the user id in the session too.

Re: User Profile tutorial

Posted: Fri Oct 28, 2011 12:50 pm
by wignall6
How would I store two values in the session?

Re: User Profile tutorial

Posted: Fri Oct 28, 2011 5:58 pm
by jacek
wignall6 wrote:How would I store two values in the session?

In the exact same was as you store one.

[syntax=php]$_SESSION['thing_1'] = 'value_1';
$_SESSION['thing_2'] = 'value_2';[/syntax]

Re: User Profile tutorial

Posted: Sun Oct 30, 2011 11:29 am
by wignall6
Would this work for getting the user_id in your login system?

[syntax=php]
$_SESSION['user_id'] = htmlentities($_GET['user_id']);
[/syntax]

Re: User Profile tutorial

Posted: Sun Oct 30, 2011 8:55 pm
by jacek
Depends how you are using it, probably not, since you will not likely have the id in the url.

There is no need for htmlentities either.