User Profiles - Edit Profile Not Working
Posted: Mon Dec 10, 2012 8:02 pm
Me again, i'm having a problem with the edit_profile page, firstly, my location, email and about me are not in the textfields (<?php echo $user_info['email']; ?>) and also when i click update, the 'Your profile has been changed' message doesn't appear.
Here's my .php files.
Edit_profile.php
Here's my .php files.
Edit_profile.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 have entered is invalid.';
}
if (preg_math('#"[a-z0-9 ]+S#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['uid']);
}
?>
<html>
<head>
<style type="text/css">
.round{
border-radius:25px;
-moz-border-radius:25px; /* Firefox 3.6 and earlier */
padding:10px;
background:yellow;
border: 2px dotted red;
}
</style>
<title><?php echo $_SESSION['username']; ?>'s Profile - Edit your profile</title>
</head>
<body>
<center>
<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>
<center>
<form action="" method="post">
<div>
<label for="email">Email:</label>
<br>
<input type"text" name="email" id="email" class="round" value="<?php echo $user_info['email']; ?>" />
</div>
<div>
<label for="location">Location:</label>
<br>
<input type"text" name="email" id="email" class="round" value="<?php echo $user_info['location']; ?>" />
</div>
<div>
<label for="about">About Me:</label>
<br>
<textarea name="about" id="about" rows="14" class="round" cols="50"><?php echo strip_tags($user_info['about']); ?></textarea>
</div>
<div>
<input type="submit" value="Update" />
</div>
</form>
</body>
</html>
Profile.php
<?php
include('core/init.inc.php');
$user_info = fetch_user_info($_GET['uid']);
?>
<?php
mysql_connect("localhost","root","*hello*");
mysql_select_db("commentbox");
$name=strip_tags(@$_POST['name']);
$comment=strip_tags(@$_POST['comment']);
$submit=@$_POST['submit'];
$dbLink = mysql_connect("localhost", "root", "jdjjjj");
mysql_query("SET character_set_client=utf8", $dbLink);
mysql_query("SET character_set_connection=utf8", $dbLink);
if($submit)
{
if($name&&$comment)
{
$insert=mysql_query("INSERT INTO commenttable (name,comment) VALUES ('$name','$comment') ");
}
else
{
echo "Please fill in <b>all</b> the fields.";
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
div.ex
{
width:220px;
padding:10px;
border:5px solid gray;
margin:0px;
}
</style>
<title><?php echo $user_info['username']; ?>'s Profile - GameCrayz</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>About me:<br><?php echo $user_info['about']; ?></p>
<a href='edit_profile.php'>Edit profile</a>
<?php
}
?>
</div>
<div class="ex">
<center>
<form action="" method="POST">
<table>
<tr><td>Name: <br><input type="text" name="name" placeholder='Enter your name...' style="width:150px;height:50px;font-family:cursive;border:double 12px #6DB72C;"/></td></tr>
<tr><td colspan="2">Comment: </td></tr>
<tr><td colspan="5"><textarea name="comment" rows="5" cols="50" style="width:200px;height:100px;font-family:cursive;border:double 12px #6DB72C;" placeholder='Enter a comment...'></textarea></td></tr>
<tr><td colspan="2"><input type="submit" name="submit" value='Comment'></td></tr>
</table>
</form>
<?php
$dbLink = mysql_connect("localhost", "root", "...");
mysql_query("SET character_set_results=utf8", $dbLink);
mb_language('uni');
mb_internal_encoding('UTF-8');
$getquery=mysql_query("SELECT * FROM commenttable ORDER BY id DESC");
while($rows=mysql_fetch_assoc($getquery))
{
$id=$rows['id'];
$name=$rows['name'];
$comment=$rows['comment'];
echo $name . ':<br/>' . '</br>' . $comment . '' . '<br/>' . '<hr size="1"/>'
;}
?>
</div>
</body>
</html>
User_List.php
<?php
include('core/init.inc.php');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registered Users</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>
Init.inc.php
<?php
session_start();
mysql_connect('localhost', 'root', '...');
mysql_select_db('phplogin');
$path = dirname(__FILE__);
include("{$path}/inc/user.inc.php");
$_SESSION['uid'] = 1;
?>
User.inc.php
<?php
//fetches all of the users from the table
function fetch_users(){
$result = mysql_query('SELECT `ID` AS `id`, `Username` AS `username` FROM `users`');
$users = array();
while (($row = mysql_fetch_assoc($result)) !== false){
$users[] = $row;
}
return $users;
}
//fetches profile info for the given user
function fetch_user_info($uid){
$uid = (int)$uid;
$sql = "SELECT
`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 `users`
WHERE `ID` = {$uid}";
$result = mysql_query($sql);
return mysql_fetch_assoc($result);
}
//updates the current users 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(htmlentities($location));
$sql = "UPDATE `users` SET
`user_email` = '{$email}'
`user_about` = '{$about}'
`user_location` = '{$location}'
WHERE `user_id` = {$_SESSION['uid']}";
mysql_query($sql);
}
?>