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! Quote Link to comment 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] :) Quote Link to comment 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. Quote Link to comment 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...... ;) Quote Link to comment 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! Quote Link to comment Share on other sites More sharing options...
trq Posted December 17, 2006 Share Posted December 17, 2006 Post your current code. Quote Link to comment 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] Quote Link to comment 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) Quote Link to comment Share on other sites More sharing options...
supermerc Posted December 17, 2006 Author Share Posted December 17, 2006 its called description Quote Link to comment 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 Quote Link to comment 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] ;) Quote Link to comment Share on other sites More sharing options...
supermerc Posted December 17, 2006 Author Share Posted December 17, 2006 works thx alot Quote Link to comment Share on other sites More sharing options...
matto Posted December 17, 2006 Share Posted December 17, 2006 no worries.... ;) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.