supermerc Posted December 17, 2006 Share Posted December 17, 2006 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]<?phpsession_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 processingif(count($errors) > 0){echo '<b>ERRORS:</b><br />';foreach($errors as $err){echo $err . '<br />';}}else{// everything is ok, update the DBmysql_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 More sharing options...
matto Posted December 17, 2006 Share Posted December 17, 2006 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 https://forums.phpfreaks.com/topic/31017-solved-help-with-user-profiles/#findComment-143126 Share on other sites More sharing options...
supermerc Posted December 17, 2006 Author Share Posted December 17, 2006 I know that those need to be updated but i dont know how, i tried some but nothing worked. Link to comment https://forums.phpfreaks.com/topic/31017-solved-help-with-user-profiles/#findComment-143133 Share on other sites More sharing options...
matto Posted December 17, 2006 Share Posted December 17, 2006 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 https://forums.phpfreaks.com/topic/31017-solved-help-with-user-profiles/#findComment-143144 Share on other sites More sharing options...
supermerc Posted December 17, 2006 Author Share Posted December 17, 2006 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 https://forums.phpfreaks.com/topic/31017-solved-help-with-user-profiles/#findComment-143152 Share on other sites More sharing options...
trq Posted December 17, 2006 Share Posted December 17, 2006 Post your current code. Link to comment https://forums.phpfreaks.com/topic/31017-solved-help-with-user-profiles/#findComment-143155 Share on other sites More sharing options...
supermerc Posted December 17, 2006 Author Share Posted December 17, 2006 Ok this is what i got now[code]<?phpsession_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 processingif(count($errors) > 0){echo '<b>ERRORS:</b><br />';foreach($errors as $err){echo $err . '<br />';}}else{// everything is ok, update the DBmysql_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 https://forums.phpfreaks.com/topic/31017-solved-help-with-user-profiles/#findComment-143159 Share on other sites More sharing options...
matto Posted December 17, 2006 Share Posted December 17, 2006 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 https://forums.phpfreaks.com/topic/31017-solved-help-with-user-profiles/#findComment-143160 Share on other sites More sharing options...
supermerc Posted December 17, 2006 Author Share Posted December 17, 2006 its called description Link to comment https://forums.phpfreaks.com/topic/31017-solved-help-with-user-profiles/#findComment-143163 Share on other sites More sharing options...
supermerc Posted December 17, 2006 Author Share Posted December 17, 2006 ok so i did wat u said[code]<?phpsession_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 processingif(count($errors) > 0){echo '<b>ERRORS:</b><br />';foreach($errors as $err){echo $err . '<br />';}}else{// everything is ok, update the DBmysql_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 https://forums.phpfreaks.com/topic/31017-solved-help-with-user-profiles/#findComment-143165 Share on other sites More sharing options...
matto Posted December 17, 2006 Share Posted December 17, 2006 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 https://forums.phpfreaks.com/topic/31017-solved-help-with-user-profiles/#findComment-143166 Share on other sites More sharing options...
supermerc Posted December 17, 2006 Author Share Posted December 17, 2006 works thx alot Link to comment https://forums.phpfreaks.com/topic/31017-solved-help-with-user-profiles/#findComment-143175 Share on other sites More sharing options...
matto Posted December 17, 2006 Share Posted December 17, 2006 no worries.... ;) Link to comment https://forums.phpfreaks.com/topic/31017-solved-help-with-user-profiles/#findComment-143184 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.