Adding a new field.


Whenever i add new field name* you can use whatever you want but make sure its the case world all the way through.
Updating the database-
PHP Code
  1. ALTER TABLE `members` ADD `*New Field Name*` VARCHAR( 225 ) NOT NULL,


Find this is your members.php file.
PHP Code
  1. <b>$user[username]\'s Profile</b><br><br>
  2. Email: $user[email]<br>
  3. Location: $user[location]<br>
  4. Sex: $user[sex]<br>
  5. Age: $user[age]


and replace with
PHP Code
  1.  
  2. <b>$user[username]\'s Profile</b><br><br>
  3. Email: $user[email]<br>
  4. Location: $user[location]<br>
  5. Sex: $user[sex]<br>
  6. Age: $user[age]<br>
  7. *new field name*: $user[new field name*]


Next find this in your editprofile.php file.

PHP Code
  1. Sex: <select size=\'1\' name=\'sex\' value=\'$user[sex]\'>
  2. <option value=\'Male\' \"; if($user[sex] == Male) {
  3. echo \"selected\"; }
  4. echo \">Male</option>
  5. <option value=\'Female\' \"; if($user[sex] == Female) {
  6. echo \"selected\"; }
  7. echo \">Female</option>
  8. </select><br>


now replace it with

PHP Code
  1. Sex: <select size=\'1\' name=\'sex\' value=\'$user[sex]\'>
  2. <option value=\'Male\' \"; if($user[sex] == Male) {
  3. echo \"selected\"; }
  4. echo \">Male</option>
  5. <option value=\'Female\' \"; if($user[sex] == Female) {
  6. echo \"selected\"; }
  7. echo \">Female</option>
  8. </select><br>
  9. *new field name*: <input type=\'text\' name=\'*new field name*\' size=\'30\' maxlength=\'40\' value=\'$user[*new field name*]\'>



thats how you add a new field to the members database enjoy :)
SkillMaster's Avatar
Views:
3,028
Rating:
Posted on Saturday 26th April 2008 at 11:04 PM
jambomb
jambomb's Avatar
wow awsum
Posted on Monday 7th April 2008 at 11:57 PM
DanielXP
DanielXP's Avatar
ALTER TABLE `members` ADD `msn` VARCHAR( 225 ) NOT NULL;
Posted on Monday 7th April 2008 at 08:11 PM
UrbanTwitch
UrbanTwitch's Avatar
Never mind I got it. Thanks Pheeonix. But how do you add another thing in like ALTER TABLE `siteusers` ADD `msn` VARCHAR( 225 ) NOT NULL; into the current DB?
Posted on Monday 7th April 2008 at 07:10 AM
test
test's Avatar
urban post ur edit profile file so people can see
Posted on Monday 7th April 2008 at 02:43 AM
UrbanTwitch
UrbanTwitch's Avatar
I get "Invalid Sex Input" when I get edit my profile.
Posted on Friday 1st June 2007 at 08:42 PM
MCP
MCP's Avatar
Awesome. Phoenix thanks sooo much. The fields are updating the DB now. :)
Posted on Thursday 31st May 2007 at 06:57 PM
Phoenixx
Phoenixx's Avatar
Here the edited members.php of the tutorial, change all *yourfield* with your field name
PHP Code
  1. <?php
  2. session_start(); //allows session
  3. include "config.php";
  4. echo "<center>";
  5. if(isset($_GET['user'])){ //if there trying to view a profile
  6. //gets the user name and makes it safe
  7. $username = addslashes($_GET[user]);
  8. //querys the db to find the username
  9. $getuser = mysql_query("SELECT * FROM `members` WHERE `username` = '$username'");
  10. //checks see if the username exists in the db
  11.  
  12. $usernum = mysql_num_rows($getuser);
  13. //if it don't exist
  14. if ($usernum == 0)
  15.  
  16. {
  17. //don't exist
  18.  
  19. echo ("User Not Found");
  20.  
  21. }
  22. //if it does exist then show there profile
  23. else
  24. {
  25. $user = mysql_fetch_array($getuser);
  26. echo "<fieldset style='width: 350'>
  27. <b>$user[username]'s Profile</b><br><br>
  28. Email: $user[email]<br>
  29. Location: $user[location]<br>
  30. Sex: $user[sex]<br>
  31. Age: $user[age]<br>
  32. *yourfield*: $user[*yourfield*]
  33. </fieldset>";
  34.  
  35. }
  36. }
  37. else
  38. {
  39. //gets all the members from the database
  40. $getusers = mysql_query("SELECT * FROM `members` ORDER BY `id` ASC") or die(mysql_error());
  41. //loops there name out
  42. while ($user = mysql_fetch_array($getusers))
  43. {
  44. echo "<a href='members.php?user=$user[username]'>$user[username]</a><br>";
  45. }
  46. }
  47. echo "<center>";
  48. ?>


Here the edited editprofile.php of the tutorial. of course, change all *yourfield* to your field name
PHP Code
  1. <?php
  2. session_start(); //allows session
  3. include "config.php";
  4. echo "<center>";
  5. //checks see if there logged in
  6. if($logged[id])
  7. {
  8. if(isset($_GET['update'])){
  9. $email = addslashes(htmlspecialchars($_POST[email]));
  10. $location = addslashes(htmlspecialchars($_POST[location]));
  11. $age = (int)addslashes(htmlspecialchars($_POST[age]));
  12. $sex = addslashes(htmlspecialchars($_POST[sex]));
  13. $*yourfield* = addslashes(htmlspecialchars($_POST[*yourfield*]));
  14. //checks the sex if its ok
  15. if(($sex == "Male") || ($sex == "Female")){
  16. //updates there profile in the db
  17. $update = mysql_query("UPDATE `members` SET `email` = '$email', `sex` = '$sex',`*yourfield*` = '$*yourfield*', `age` = '$age', `location` = '$location' WHERE `username` = '$logged[username]'");
  18. echo "Profile updated!";
  19. }
  20. //if the sex is invalid
  21. else
  22. {
  23. echo "Invalid sex input!";
  24. }
  25. }
  26. else
  27. {
  28. $getuser = mysql_query("SELECT * FROM `members` WHERE `username` = '$logged[username]'");
  29. $user = mysql_fetch_array($getuser);
  30. echo "<form action='editprofile.php?update' method='post'>
  31. <fieldset style='width: 350'>
  32. Email: <input type='text' name='email' size='30' maxlength='55' value='$user[email]'><br>
  33. Location: <input type='text' name='location' size='30' maxlength='40' value='$user[location]'><br>
  34. Age: <input type='text' name='age' size='3' maxlength='3' value='$user[age]'><br>
  35. Sex: <select size='1' name='sex' value='$user[sex]'>
  36. <option value='Male' "; if($user[sex] == Male) {
  37. echo "selected"; }
  38. echo ">Male</option>
  39. <option value='Female' "; if($user[sex] == Female) {
  40. echo "selected"; }
  41. echo ">Female</option>
  42. </select><br>
  43. *yourfield*: <input type='text' name='*yourfield*' size='30' maxlength='40' value='$user[*yourfield*]'><br>
  44. <input type='submit' value='Update'>
  45. </fieldset></form>";
  46. }
  47. }
  48. else
  49. {
  50. echo "You are not logged in.";
  51. }
  52. echo "<center>";
  53. ?>

add the new field to the db before you're running the files. now it should go like planned.
Posted on Thursday 31st May 2007 at 06:24 PM
MCP
MCP's Avatar
That table is altered now and I have added the necessary code changes to members.php and editprofile.php but still the fields are not updated. The info is not logged into the SQL DB.
Posted on Wednesday 30th May 2007 at 07:15 PM
Phoenixx
Phoenixx's Avatar
Search in editprofile.php for the lines:

if(isset($_GET['update'])){
$email = addslashes(htmlspecialchars($_POST[email]));

Then add in a new line

$*yourthing* = addslashes(htmlspecialchars($_POST[*yourthing*]));

for all new entries.
After that search for

$update = mysql_query("UPDATE `members` SET `email` = '$email', `sex` = '$sex',
and so on...

Now put in:

`*yourthing*` = '$*yourthing*',

Look for the "," don't doublepost it there
Posted on Wednesday 30th May 2007 at 07:06 PM
MCP
MCP's Avatar
The problem I am having now is in the editprofile.php

I entered the code exactly as stated on this tutorial but it goes blank after updating it.