User profile No Data Displayed

Post here is you are having problems with any of the tutorials.
Post Reply
User avatar
kalipsso
Posts: 30
Joined: Thu Jun 09, 2011 3:03 pm
Location: Bucharest
Contact:

User profile No Data Displayed

Post by kalipsso »

Got it :)
Now i run into another issue...the edit_profile form.
is not displaying the values of the fields...
[syntax=php]
<?php

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

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

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<!--<link rel="stylesheet" type="text/css" href="ext/css/style.css">-->
<style type="text/css">
form {margin: 10px 0px 0px 0px; }
form div {float:left; clear:both; margin:0px 0px 4px 0px; }
label {float:left; width:100px; }
input[type="text"], textarea {float:left; width:400px; }
input[type="submit"] {margin:10px 0px 0px 100px; }
</style>
<title>Edit Your Profile</title>
</head>
<body>
<div>
<?php



?>
</div>
<form action="" method="POST">
<div>
<label for="firstname">Firstname:</label>
<input type="text" name="firstname" id="firstname" value="<?php echo $user_info['firstname']; ?>" />
</div>
<div>
<label for="email">Email:</label>
<input type="text" name="email" id="email" value="<?php echo $user_info['email']; ?>" />
</div>
<div>
<label for="location">Location:</label>
<input type="text" name="location" id="location" value="<?php echo $user_info ['location']; ?>" />
</div>
<div>
<label for="about">About:</label>
<textarea name="about" id="about" rows="14" cols="50"><?php echo $user_info ['about']; ?></textarea>
</div>
<div>
<input type="submit" value="Update" />
</div>
</form>
</body>
</html>
[/syntax]
this is my edit_profile.php page.
what did i do wrong?
remember that i am using it with the register/login script and uses the same database called user_system...
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: User profile No Data Displayed

Post by jacek »

You can try adding

[syntax=php]var_dump($user_info);[/syntax]
after that variable is defined to see what the function is actually returning.

Also can you make sure you use the php button when posting code, and not the code tags.
Image
User avatar
kalipsso
Posts: 30
Joined: Thu Jun 09, 2011 3:03 pm
Location: Bucharest
Contact:

Re: User profile No Data Displayed

Post by kalipsso »

jacek wrote:You can try adding

[syntax=php]var_dump($user_info);[/syntax]
after that variable is defined to see what the function is actually returning.

Also can you make sure you use the php button when posting code, and not the code tags.

is not about displaying the data after submitting the form...is about that i get no user info in the form, the values from the database value="<?php echo $user_info['firstname']; ?>
User avatar
kalipsso
Posts: 30
Joined: Thu Jun 09, 2011 3:03 pm
Location: Bucharest
Contact:

Re: User profile No Data Displayed

Post by kalipsso »

after i add [syntax=php]var_dump($user_info); [/syntax]the result returned NULL.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: User profile No Data Displayed

Post by jacek »

Okay, can you post the code of the function then ? It looks like that is where the problem will be.
Image
User avatar
kalipsso
Posts: 30
Joined: Thu Jun 09, 2011 3:03 pm
Location: Bucharest
Contact:

Re: User profile No Data Displayed

Post by kalipsso »

does init.inc.php from user system conflicts wit the init.inc.php from the user profile ?

init.inc.php from user register/login:

[syntax=php]<?php

session_start();

$exceptions = array('register', 'login', 'activate');

$page = substr(end(explode('/', $_SERVER['SCRIPT_NAME'])), 0, -4);

mysql_connect('localhost', 'root', '12345678');
mysql_select_db('user_system');

$path = dirname(__FILE__);

include("{$path}/inc/user.inc.php");

if (isset($_COOKIE['username'], $_COOKIE['password']) && isset($_SESSION['username']) === false){
if (valid_credentials($_COOKIE['username'], $_COOKIE['password'])){
$_SESSION['username'] = htmlentities($_COOKIE['username']);

setcookie('username', $_COOKIE['username'], time() + 604800);
setcookie('password', sha1($_COOKIE['password'], time() + 604800));
}
}

if (in_array($page, $exceptions) === false){
if (isset($_SESSION['username']) === false){
header('Location: login.php');
die();
}
}



?>[/syntax]

init.inc.php from user profile
[syntax=php]<?php

mysql_connect('localhost', 'root', '12345678');
mysql_select_db('user_system');

$path = dirname(__FILE__);

include("{$path}/inc/user.inc.php");

$_SESSION['uid'] = 1;

?>[/syntax]
can these 2 be mixed together?
Thanks!
And user.inc.php from reg/login can be mixed with user.inc.php from user profile?

user.inc.php from login-reg
[syntax=php]<?php

//checks if given username exists in the database.
function user_exists($user){
$user = mysql_real_escape_string($user);

$total = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `user_name` = '{$user}'");

return (mysql_result($total, 0) == '1') ? true : false;
}

//checks if given username and password conbination is valid.
function valid_credentials($user, $pass){
$user = mysql_real_escape_string($user);
$pass = mysql_real_escape_string($pass);

$total = mysql_query("SELECT COUNT('user_id') FROM `users` WHERE `user_name` = '{$user}' AND `user_password` = '{$pass}'");

return (mysql_result($total, 0) == '1') ? true : false;
}

//checks if the given user account is active.
function is_active($user){
$user = mysql_real_escape_string($user);

$sql = "SELECT
COUNT(`user_activations`.`user_id`)
FROM `users`
INNER JOIN `user_activations`
ON `users`.`user_id`=`user_activations`.`user_id`
WHERE `users`.`user_name` = '{$user}'";

$result = mysql_query($sql);

return (mysql_result($result, 0) == '0') ? true : false;
}

//activates the account related to the given activation code.
function activate_account($aid) {
$aid = mysql_real_escape_string($aid);

mysql_query("DELETE FROM `user_activations` WHERE `activation_code` = '{$aid}'");
}

//adds user to the database.
function add_user($user, $email, $pass){
$user = mysql_real_escape_string(htmlentities($user));
$email = mysql_real_escape_string($email);
$pass = sha1($pass);

$charset = array_flip(array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9)));
$aid = implode('', array_rand($charset, 10));

$body = <<<EMAIL

Hi.
Thanks for registering, before you login you need to activate your account.

To do that, simply click the following link.

D:/XAMPP/xampp/htdocs/Better/activate.php?aid={$aid}


EMAIL;

mail($email, 'Your new account at CupidCity.com', $body, 'From: no-reply@cupidcity.com');

mysql_query("INSERT INTO `users` (`user_name`, `user_password`,`user_email`) VALUES ('{$user}', '{$pass}', '{$email}')");

$user_id = mysql_insert_id();

mysql_query("INSERT INTO `user_activations` (`user_id`, `activation_code`) VALUES ({$user_id}, '{$aid}')");
}


?>[/syntax]

user.inc.php from user profiles:
[syntax=php]<?php

//fetches all users from the table.
function fetch_users(){
$result = mysql_query('SELECT `user_id` AS `id`, `user_name` AS `username` FROM `users`');

$users = array();

while (($row = mysql_fetch_assoc($result)) !== false){
$users[] = $row;
}

return $users;
}

//fatches profile information for the given user.
function fetch_user_info($uid){
$uid = (int)$uid;

$sql = "SELECT
`user_name` 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 user profile info.
function set_profile_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]
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: User profile No Data Displayed

Post by jacek »

kalipsso wrote:does init.inc.php from user system conflicts wit the init.inc.php from the user profile ?

the point of the init file is that it does things that are always needed, so you should not have more than one init file.

Before the call to the fetch_user_info() function can you try var_dump($_SESSION['uid']) to see if that has the value that you expect ?
Image
User avatar
kalipsso
Posts: 30
Joined: Thu Jun 09, 2011 3:03 pm
Location: Bucharest
Contact:

Re: User profile No Data Displayed

Post by kalipsso »

jacek wrote:
kalipsso wrote:does init.inc.php from user system conflicts wit the init.inc.php from the user profile ?

the point of the init file is that it does things that are always needed, so you should not have more than one init file.

Before the call to the fetch_user_info() function can you try var_dump($_SESSION['uid']) to see if that has the value that you expect ?

in what file to add that?
Thanks..
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: User profile No Data Displayed

Post by jacek »

the profile page I guess, which ever you posted in the first post of this topic.
Image
User avatar
kalipsso
Posts: 30
Joined: Thu Jun 09, 2011 3:03 pm
Location: Bucharest
Contact:

Re: User profile No Data Displayed

Post by kalipsso »

jacek wrote:the profile page I guess, which ever you posted in the first post of this topic.

That is the edit_profile.php file..
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: User profile No Data Displayed

Post by jacek »

kalipsso wrote:That is the edit_profile.php file..

Okay, try it there then.
Image
User avatar
kalipsso
Posts: 30
Joined: Thu Jun 09, 2011 3:03 pm
Location: Bucharest
Contact:

Re: User profile No Data Displayed

Post by kalipsso »

jacek wrote:
kalipsso wrote:That is the edit_profile.php file..

Okay, try it there then.

i get an error on the line i put the code...
User avatar
kalipsso
Posts: 30
Joined: Thu Jun 09, 2011 3:03 pm
Location: Bucharest
Contact:

Re: User profile No Data Displayed

Post by kalipsso »

OK.
I added this code in init.inc.php from user register/login system [syntax=php]$_SESSION['uid'] = 12;[/syntax]
This is the result:
Image
if i remove that code, the edit form is empty..
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: User profile No Data Displayed

Post by jacek »

you cant have output before the session_start function, you will have to add it after the include.
Image
User avatar
kalipsso
Posts: 30
Joined: Thu Jun 09, 2011 3:03 pm
Location: Bucharest
Contact:

Re: User profile No Data Displayed

Post by kalipsso »

jacek wrote:you cant have output before the session_start function, you will have to add it after the include.

I found the error source...
I had a space before

[syntax=php]<?php include('core/init.inc.php'); ?>[/syntax]
But still...i cant make it reflect the logged in user details...
what to do?
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: User profile No Data Displayed

Post by jacek »

kalipsso wrote:what to do?

I answered this in your other topic

viewtopic.php?f=7&t=306#p3180
Image
User avatar
kalipsso
Posts: 30
Joined: Thu Jun 09, 2011 3:03 pm
Location: Bucharest
Contact:

Re: User profile No Data Displayed

Post by kalipsso »

Alright.
i manage to connect the 2 scripts together..with no errors...
Post Reply