profile editing errors

Post here is you are having problems with any of the tutorials.
Post Reply
Thunderbob
Posts: 46
Joined: Sat Jun 30, 2012 12:31 pm

profile editing errors

Post by Thunderbob »

sorry guys for asking for so much in one day.
So thanks to an awesome individual within this forum I was able to fix one of the most annoying
errors. The profile page set-up is looking good.
I can change the uid at the end of the url and I am linked to a different profile page.
Now I want the user who is logged in to be able to edit their information.

I'm testing out the code from the online video and no luck.
The form shows up nice and fine but once I hit submit ...nothing changes.
Also the form only shows the info for the user who's id = 1


Here is the profile editing page [syntax=php]<?php
include('init.inc.php');
if (isset($_POST['email'], $_POST['location'], $_POST['about'], $_POST['gender'], $_POST['username'])){
$errors = array();

if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)=== false)
{
$errors[] = 'The email address you entered is not valid or is already taken.';
}



if(empty($errors))
{ set_profile_info($_POST['email'], $_POST['location'],
$_POST['about'], $_POST['gender'], $_POST['username']);
}
$user_info = array(
'email' => htmlentities($_POST['email']),
'about' => htmlentities($_POST['about']),
'gender' => htmlentities($_POST['gender']),
'location' => htmlentities($_POST['location']),
'username' => htmlentities($_POST['username'])
);
}
else{
$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://w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" concent=text/html; charset=utf-8" />
<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="username"> Username: </label>
<input type="text" name="username" id="username" value="<?php echo $user_info['username']; ?>" />
</div>

<div>
<label for="email"> Email: </label>
<input type="text" name="email" id="email" value="<?php echo $user_info['email']; ?>" />
</div>

<div>
<label for="gender"> Gender: </label>
<input type="text" name="gender" id="gender" value="<?php echo $user_info['gender']; ?>" />
</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 $user_info['about']; ?> </textarea>
</div>

<div>
<input type="submit" value="Update" />
</div>
</form>



</body>
</html>[/syntax]

here is the backend file

[syntax=php]
<?php
function fetch_users(){
$result = mysql_query("SELECT `id_user` AS `id`, `username` AS `username` FROM `fgusers3` ");
$users = array();
while (($row = mysql_fetch_assoc($result)) !== false){
$users[] = $row;
}echo mysql_error();
return $users;
}
function fetch_user_info($uid){
$uid = (int)$uid;
$sql = "SELECT
`username` AS `username`,
`user_about` AS `about`,
`user_location` AS `location`,
`user_gender` AS `gender`
FROM `fgusers3`
WHERE `id_user`= '{$uid}'" ;
$result = mysql_query($sql);
return mysql_fetch_assoc($result);
}

// updates the current users profile information.
function set_profile_info($email, $location, $about, $gender, $username){
$email = mysql_real_escape_string(htmlentities($email));
$about = mysql_real_escape_string(htmlentities($about));
$location = mysql_real_escape_string(htmlentities($location));
$gender = mysql_real_escape_string(htmlentities($gender));
$username = mysql_real_escape_string(htmlentities($username));

$sql = "UPDATE fgusers3 SET
`user_email` = `{$email}`,
`user_about` = `{$about}`,
`user_location` = `{$location}`,
`gender` = `{$gender}`,
`username` = `{$username}`
{$_SESSION['uid']}";

mysql_query($sql);
}
?>[/syntax]


I wanted to take the tutorial a step further by allowing users to change their username and gender haha.
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: profile editing errors

Post by Temor »

well, this sql statement needs a WHERE clause.
[syntax=php] $sql = "UPDATE fgusers3 SET
`user_email` = `{$email}`,
`user_about` = `{$about}`,
`user_location` = `{$location}`,
`gender` = `{$gender}`,
`username` = `{$username}`
WHERE
`user_id` = {$_SESSION['uid']}";[/syntax]

this will only change the information for the logged in user.
Thunderbob
Posts: 46
Joined: Sat Jun 30, 2012 12:31 pm

Re: profile editing errors

Post by Thunderbob »

it didn't change anything.
Can I close down this topic and come back to it?

I think this is an issue with the session scripting that I am using.
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: profile editing errors

Post by Temor »

What's wrong with the sessions?
Post Reply