[Help Me]User Profile

Post here is you are having problems with any of the tutorials.
Post Reply
idevlop
Posts: 6
Joined: Wed Jul 06, 2011 8:20 am

[Help Me]User Profile

Post by idevlop »

please help me...its nothing on the webpage
user.inc.php
<?php
//fetches all of the user from the table
function fetch_user()
{
	$result = mysql_query('SELECT `user_id` AS `id`,`user_username` AS `username` FROM `user_profile` ');
    $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 `user_profile`
	           WHERE `user_id` = {$uid}";
	
	$result = mysql_query($sql);
	
	return mysql_fetch_assoc($result);
}
//updates the current users profile info
function set_profile_info($email,$about, $loaction)
{
	$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);
			   
	
}
?>
init.inc.php
<?php
session_start();
mysql_connect('localhost','root','*****');
mysql_select_db('user_profile');

$path = dirname(_FILE_);

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

$_SESSION['uid']=1;

?>
edit_profile.php
<?php
include('core/init.inc.php');
if(isset ($_POST['email'],$_POST['location'],$_POST['about']))
{
	$error = array();
	
	if(filter_var($_POST['email'].FILTER_VALIDATE_EMAIL)=== false)
	{
		$errors[] ='The email adress you entered is not valid.'; 
	}
	
	if(preg_match('#^[a-z0-9 ]+$#1'.$_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['uid']);
}
?>
<html>
<head>
	<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
		if (isset($errors)=== false)
		{
			echo 'Click Update to edit your profile.';
		}else if(empty[$errors]){
			echo 'Your profile has been updated/';
			
		}else{
			echo '<ul><li>'.implode('</li></li>'. $errors).'</li></ul>';
		}
		?>
	</div>
	<form action="" method="post">
		<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 Me:</label>
			<textarea name="about" id="about" rows="14" cols="50"><?php echo strip_tags($user_info['about']); ?></textarea>
		</div>
		<div>
			<input type="submit" value="Update"/>
		</div>
</body>	
</html>
Profile.php
<?php
include('core/init.inc.php');

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

?>
<html>
<head>
	<title><?php echo $user_info['username']; ?>'s Profile</title>
</head>
<body>
	<div>
		<?php
		if ($user_info === false)
		{
			echo 'That user does not 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>
User_list.php
<?php
include('core/init.inc.php');
?>
<html>
<head>
	<title>Registered User</title>
</head>
<body>
	<div>
		<?php
		foreach (fetch_users()as $user)
		{
			?>
			<p>
			  <a href="profile.php?uid=<?php echo $user['id'];?>"><?php echo $user['username']; ?></a>
			</p>
			<?php
		}
		?>
	</div>
</body>	
</html>
What is wrong here?...please help me
conradk
Posts: 117
Joined: Tue Jul 05, 2011 10:41 pm

Re: [Help Me]User Profile

Post by conradk »

Hello idevlop,

Before trying anything else, try adding this to the top of your pages while testing:
ini_set('display_errors',1);
error_reporting(E_ALL);
If any error appears, please paste it here :)

Best regards,
CK
idevlop
Posts: 6
Joined: Wed Jul 06, 2011 8:20 am

Re: [Help Me]User Profile

Post by idevlop »

this ....

Notice: Use of undefined constant _FILE_ - assumed '_FILE_' in C:\www\webroot\profile\core\init.inc.php on line 6

Warning: include(./inc/user.inc.php) [function.include]: failed to open stream: No such file or directory in C:\www\webroot\profile\core\init.inc.php on line 8

Warning: include() [function.include]: Failed opening './inc/user.inc.php' for inclusion (include_path='.;C:/www/webroot/;C:/www/php5/includes/') in C:\www\webroot\profile\core\init.inc.php on line 8

Fatal error: Call to undefined function fetch_user_info() in C:\www\webroot\profile\page.php on line 7
idevlop
Posts: 6
Joined: Wed Jul 06, 2011 8:20 am

Re: [Help Me]User Profile

Post by idevlop »

yeah...i have new problem....i can't update my profile...it blank web page
conradk
Posts: 117
Joined: Tue Jul 05, 2011 10:41 pm

Re: [Help Me]User Profile

Post by conradk »

Let's, fix the errors first. We'll see about the blank page afterwards.
idevlop wrote:Notice: Use of undefined constant _FILE_ - assumed '_FILE_' in C:\www\webroot\profile\core\init.inc.php on line 6
Try '__FILE__' instead of '_FILE_' ;)

idevlop wrote: Warning: include(./inc/user.inc.php) [function.include]: failed to open stream: No such file or directory in C:\www\webroot\profile\core\init.inc.php on line 8
Wrong path here. Fix the path on line 8.
idevlop wrote: Warning: include() [function.include]: Failed opening './inc/user.inc.php' for inclusion (include_path='.;C:/www/webroot/;C:/www/php5/includes/') in C:\www\webroot\profile\core\init.inc.php on line 8
Not quite sure what this is. Fix the previous error and this one might disappear also.
idevlop wrote: Fatal error: Call to undefined function fetch_user_info() in C:\www\webroot\profile\page.php on line 7
What is page.php ?
idevlop
Posts: 6
Joined: Wed Jul 06, 2011 8:20 am

Re: [Help Me]User Profile

Post by idevlop »

page is profile i just replace it.....
i have new problem now,....edit_profile.php
Image
it blank
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: [Help Me]User Profile

Post by jacek »

A completely blank page usually means you have a syntax error that php is not telling you about. You can make it tell you about them by setting error_reporting to E_ALL, either by editing your php.ini file or by doing this
conradk wrote:Before trying anything else, try adding this to the top of your pages while testing:
ini_set('display_errors',1);
error_reporting(E_ALL);
Image
conradk
Posts: 117
Joined: Tue Jul 05, 2011 10:41 pm

Re: [Help Me]User Profile

Post by conradk »

There should be an error log if you use apache, right? On Ubuntu, every error is logged into /var/log/apache2/error/log.

Maybe you have something similar on Mac ?
idevlop
Posts: 6
Joined: Wed Jul 06, 2011 8:20 am

Re: [Help Me]User Profile

Post by idevlop »

yeah...i get new problem...after me click update...it appear this
Image
please help
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: [Help Me]User Profile

Post by jacek »

if(preg_match('#^[a-z0-9 ]+$#1'.$_POST['location'])=== 0)
Here you have a . (period) where you should have a , (comma) I guess the other similar error is caused by the same problem.

The third error is caused by the second one and the final one is a typo again, the function is file_exists not file_exist
Image
idevlop
Posts: 6
Joined: Wed Jul 06, 2011 8:20 am

Re: [Help Me]User Profile

Post by idevlop »

this the new problem
Image
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: [Help Me]User Profile

Post by jacek »

Stop being lazy, this error tells you almost exactly what the problem is.
Image
Post Reply