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


