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.
User Profile tutorial
Re: User Profile tutorial
Yeah, how would I make it so the page will get the userid to display the right information.
Re: User Profile tutorial
How would I store two values in the session?
Re: User Profile tutorial
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
Would this work for getting the user_id in your login system?
[syntax=php]
$_SESSION['user_id'] = htmlentities($_GET['user_id']);
[/syntax]
[syntax=php]
$_SESSION['user_id'] = htmlentities($_GET['user_id']);
[/syntax]
Re: User Profile tutorial
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.
There is no need for htmlentities either.