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
https://forums.phpfreaks.com/topic/31017-solved-help-with-user-profiles/
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]


:)



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......

;)
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!
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]
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)

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
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]

;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.