Jump to content

[SOLVED] Help with user profiles


supermerc

Recommended Posts

I followed a tutorial to add a profile to users of my site. The problem is that it only showed the email and in the edit profile i could edit it.

But i want to add a field so they could add a description to their profile. So i added the field in the database and added it to display on the profile but I need to put it in the edit_profile.php page so they can set a description.

This is my code

[code]<?php
session_start();
require("config.php");
require("func.php");
//echo some styles to spice it up...
echo
"
<style>
body
{
background: #EBEBEB;
font-family: Verdana, Arial;
font-weight: bold;
font-size: 9px;
color: #000000;
}
.register_box
{
border: 1px solid #323232;
background: #202020;
font-family: Verdana, Arial;
font-weight: bold;
font-size: 9px;
color: #FFFFFF;
}
</style>
";
if(isset($_SESSION['s_logged_n']))
{
$session_username = $_SESSION['s_username'];
// further checking...
if(username_exists($session_username))
{
$get_info = mysql_query("SELECT email FROM users WHERE username = '$session_username' LIMIT 1");
if(mysql_num_rows($get_info) > 0)
{
$user_info = mysql_fetch_assoc($get_info);
if(!isset($_POST['do_edit']))
{
echo '
<form action="edit_profile.php" method="post">
<input type="text" name="email" value="' . $user_info['email'] . '" />
<br />
<input type="submit" name="do_edit" value="Edit Your Profile" />
</form>
';
}
elseif(isset($_POST['do_edit']))
{
$email = mysql_real_escape_string($_POST['email']);
// assign all errors to an array
$errors = array();
if(empty($email))
{
$errors[] = 'Your email was empty.';
}
if(!is_valid_email($email))
{
$errors[] = 'Your email was not in a valid email format.';
}
// if array elements is greater than 0,
// then we KNOW there was an error
// else, no error, move on to processing
if(count($errors) > 0)
{
echo '<b>ERRORS:</b><br />';
foreach($errors as $err)
{
echo $err . '<br />';
}
}
else
{
// everything is ok, update the DB
mysql_query("UPDATE users SET email = '$email' WHERE username = '$session_username'");
echo 'Profile Edited.';
}
}
}
else
{
echo 'Could not find profile info for your username.';
}
}
else
{
echo 'Sorry, your session username doesnt exist.';
}
}
else
{
echo 'You must be logged in to edit your profile.';
}
?> [/code]

I tried a couple of things but im not very good at php and i just myself some errors so if anyone know what hes doing that could help me it would be creatly apreciated!
Link to comment
Share on other sites

Firstly you would need to change this to have a description field the user could fill in

[code]
<form action="edit_profile.php" method="post">
<input type="text" name="email" value="' . $user_info['email'] . '" />
<br />
<input type="submit" name="do_edit" value="Edit Your Profile" />
</form>
[/code]

and the update query would also need to update the db so you would need to change this line also to set the description field

[code]
mysql_query("UPDATE users SET email = '$email' WHERE username = '$session_username'");
[/code]

You would probably want to change this line as well, so the user could see the description when it's been updated


[code]
$get_info = mysql_query("SELECT email FROM users WHERE username = '$session_username' LIMIT 1");
[/code]


:)



Link to comment
Share on other sites

well...

[code]
<form action="edit_profile.php" method="post">
<input type="text" name="email" value="' . $user_info['email'] . '" />
<br />
<input type="" name="description" value="' . $user_info['description'] . '" />
<br/>
<input type="submit" name="do_edit" value="Edit Your Profile" />
</form>
[/code]


[code]
mysql_query("UPDATE users SET email = '$email', description = '$description' WHERE username = '$session_username'");
[/code]

[code]
$get_info = mysql_query("SELECT email, description FROM users WHERE username = '$session_username' LIMIT 1");
[/code]


note: none of this is tested, but hope you get the idea......

;)
Link to comment
Share on other sites

That partly worked.

there was no error so i was able to put something into description but when i put something in and submit the form it shows in as nothing, for exapmple I hate test in my database for description then After i enter ``This is my description`` and submited it, There was nothing in the description!
Link to comment
Share on other sites

Ok this is what i got now

[code]<?php
session_start();
require("config.php");
require("func.php");
//echo some styles to spice it up...
echo
"
<style>
body
{
background: #EBEBEB;
font-family: Verdana, Arial;
font-weight: bold;
font-size: 9px;
color: #000000;
}
.register_box
{
border: 1px solid #323232;
background: #202020;
font-family: Verdana, Arial;
font-weight: bold;
font-size: 9px;
color: #FFFFFF;
}
</style>
";
if(isset($_SESSION['s_logged_n']))
{
$session_username = $_SESSION['s_username'];
// further checking...
if(username_exists($session_username))
{
$get_info = mysql_query("SELECT email, description FROM users WHERE username = '$session_username' LIMIT 1");
if(mysql_num_rows($get_info) > 0)
{
$user_info = mysql_fetch_assoc($get_info);
if(!isset($_POST['do_edit']))
{
echo '
<form action="edit_profile.php" method="post">
<input type="text" name="email" value="' . $user_info['email'] . '" />
<br />
<input type="" name="description" value="' . $user_info['description'] . '" />
<br/>
<input type="submit" name="do_edit" value="Edit Your Profile" />
</form>
';
}
elseif(isset($_POST['do_edit']))
{
$email = mysql_real_escape_string($_POST['email']);
// assign all errors to an array
$errors = array();
if(empty($email))
{
$errors[] = 'Your email was empty.';
}
if(!is_valid_email($email))
{
$errors[] = 'Your email was not in a valid email format.';
}
// if array elements is greater than 0,
// then we KNOW there was an error
// else, no error, move on to processing
if(count($errors) > 0)
{
echo '<b>ERRORS:</b><br />';
foreach($errors as $err)
{
echo $err . '<br />';
}
}
else
{
// everything is ok, update the DB
mysql_query("UPDATE users SET email = '$email', description = '$description' WHERE username = '$session_username'");
echo 'Profile Edited.';
}
}
}
else
{
echo 'Could not find profile info for your username.';
}
}
else
{
echo 'Sorry, your session username doesnt exist.';
}
}
else
{
echo 'You must be logged in to edit your profile.';
}
?> [/code]
Link to comment
Share on other sites

oops....

this

<input type="" name="description" value="' . $user_info['description'] . '" />


s/be

<input type="text" name="description" value="' . $user_info['description'] . '" />


what did you call your database field ?

...also, you should be using $_POST['description'] rather that $description as this will fail if registered_globals are set to off (now the default)

Link to comment
Share on other sites

ok so i did wat u said

[code]<?php
session_start();
require("config.php");
require("func.php");
//echo some styles to spice it up...
echo
"
<style>
body
{
background: #EBEBEB;
font-family: Verdana, Arial;
font-weight: bold;
font-size: 9px;
color: #000000;
}
.register_box
{
border: 1px solid #323232;
background: #202020;
font-family: Verdana, Arial;
font-weight: bold;
font-size: 9px;
color: #FFFFFF;
}
</style>
";
if(isset($_SESSION['s_logged_n']))
{
$session_username = $_SESSION['s_username'];
// further checking...
if(username_exists($session_username))
{
$get_info = mysql_query("SELECT email, description FROM users WHERE username = '$session_username' LIMIT 1");
if(mysql_num_rows($get_info) > 0)
{
$user_info = mysql_fetch_assoc($get_info);
if(!isset($_POST['do_edit']))
{
echo '
<form action="edit_profile.php" method="post">
<input type="text" name="email" value="' . $user_info['email'] . '" />
<br />
<input type="text" name="description" value="' . $user_info['description'] . '" />
<br/>
<input type="submit" name="do_edit" value="Edit Your Profile" />
</form>
';
}
elseif(isset($_POST['do_edit']))
{
$email = mysql_real_escape_string($_POST['email']);
// assign all errors to an array
$errors = array();
if(empty($email))
{
$errors[] = 'Your email was empty.';
}
if(!is_valid_email($email))
{
$errors[] = 'Your email was not in a valid email format.';
}
// if array elements is greater than 0,
// then we KNOW there was an error
// else, no error, move on to processing
if(count($errors) > 0)
{
echo '<b>ERRORS:</b><br />';
foreach($errors as $err)
{
echo $err . '<br />';
}
}
else
{
// everything is ok, update the DB
mysql_query("UPDATE users SET email = '$email', description = '$description' WHERE username = '$session_username'");
echo 'Profile Edited.';
}
}
}
else
{
echo 'Could not find profile info for your username.';
}
}
else
{
echo 'Sorry, your session username doesnt exist.';
}
}
else
{
echo 'You must be logged in to edit your profile.';
}
?> [/code]

thats my code now and still not working
Link to comment
Share on other sites

Try replacing this line

[code]
mysql_query("UPDATE users SET email = '$email', description = '$description' WHERE username = '$session_username'");
[/code]

with this

[code]
mysql_query("UPDATE users SET email = '$email', description = '" . $_POST['description'] . "' WHERE username = '$session_username'");
[/code]

;)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.