Forgot Password / Register
Site Statistics
Total Members: 520
Total Tutorials: 242
Newsest User: 8884244477
Todays Unique Hits: 488
0 Users 5 Guests Online

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

ALTER TABLE `members` ADD `*New Field Name*` VARCHAR( 225 ) NOT NULL,


Find this is your members.php file.
Code

<b>$user[username]\'s Profile</b><br><br>
Email: $user[email]<br>
Location: $user[location]<br>
Sex: $user[sex]<br>
Age: $user[age]


and replace with
Code


<b>$user[username]\'s Profile</b><br><br>
Email: $user[email]<br>
Location: $user[location]<br>
Sex: $user[sex]<br>
Age: $user[age]<br>
*new field name*: $user[new field name*]


Next find this in your editprofile.php file.

Code

Sex: <select size=\'1\' name=\'sex\' value=\'$user[sex]\'>
<option value=\'Male\' \"; if($user[sex] == Male) {
echo \"selected\"; }
echo \">Male</option>
<option value=\'Female\' \"; if($user[sex] == Female) {
echo \"selected\"; }
echo \">Female</option>
</select><br>


now replace it with

Code

Sex: <select size=\'1\' name=\'sex\' value=\'$user[sex]\'>
<option value=\'Male\' \"; if($user[sex] == Male) {
echo \"selected\"; }
echo \">Male</option>
<option value=\'Female\' \"; if($user[sex] == Female) {
echo \"selected\"; }
echo \">Female</option>
</select><br>
*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
Views:
2767
Rating:
Posted on Saturday 26th April 2008 at 11:04 PM
jambomb
jambomb
wow awsum
Posted on Monday 7th April 2008 at 11:57 PM
DanielXP
DanielXP
ALTER TABLE `members` ADD `msn` VARCHAR( 225 ) NOT NULL;
Posted on Monday 7th April 2008 at 08:11 PM
UrbanTwitch
UrbanTwitch
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
urban post ur edit profile file so people can see
Posted on Monday 7th April 2008 at 02:43 AM
UrbanTwitch
UrbanTwitch
I get "Invalid Sex Input" when I get edit my profile.
Posted on Friday 1st June 2007 at 08:42 PM
MCP
MCP
Awesome. Phoenix thanks sooo much. The fields are updating the DB now. :)
Posted on Thursday 31st May 2007 at 06:57 PM
Phoenixx
Phoenixx
Here the edited members.php of the tutorial, change all *yourfield* with your field name
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
session_start
(); //allows session
include "config.php";
echo 
"<center>";
if(isset(
$_GET['user'])){ //if there trying to view a profile
//gets the user name and makes it safe
$username addslashes($_GET[user]);
//querys the db to find the username
$getuser mysql_query("SELECT * FROM `members` WHERE `username` = '$username'");
//checks see if the username exists in the db 

$usernum mysql_num_rows($getuser);
//if it don't exist 
if ($usernum == 0


//don't exist

echo ("User Not Found"); 


//if it does exist then show there profile
else
{
$user mysql_fetch_array($getuser); 
echo 
"<fieldset style='width: 350'>
<b>
$user[username]'s Profile</b><br><br>
Email: 
$user[email]<br>
Location: 
$user[location]<br>
Sex: 
$user[sex]<br>
Age: 
$user[age]<br>
*yourfield*: 
$user[*yourfield*]
</fieldset>"
;

}
}
else
{
//gets all the members from the database
$getusers mysql_query("SELECT * FROM `members` ORDER BY `id` ASC") or die(mysql_error()); 
//loops there name out
while ($user mysql_fetch_array($getusers)) 

echo 
"<a href='members.php?user=$user[username]'>$user[username]</a><br>"
}
}
echo 
"<center>";
?>


Here the edited editprofile.php of the tutorial. of course, change all *yourfield* to your field name
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
session_start
(); //allows session
include "config.php";
echo 
"<center>";
//checks see if there logged in
if($logged[id]) 

if(isset(
$_GET['update'])){
$email addslashes(htmlspecialchars($_POST[email])); 
$location addslashes(htmlspecialchars($_POST[location])); 
$age = (int)addslashes(htmlspecialchars($_POST[age])); 
$sex addslashes(htmlspecialchars($_POST[sex])); 
$*
yourfield* = addslashes(htmlspecialchars($_POST[*yourfield*]));
//checks the sex if its ok
if(($sex == "Male") || ($sex == "Female")){
//updates there profile in the db
$update mysql_query("UPDATE `members` SET `email` = '$email', `sex` = '$sex',`*yourfield*` = '$*yourfield*', `age` = '$age', `location` = '$location' WHERE `username` = '$logged[username]'");
echo 
"Profile updated!";
}
//if the sex is invalid
else
{
echo 
"Invalid sex input!";
}
}
else
{
$getuser mysql_query("SELECT * FROM `members` WHERE `username` = '$logged[username]'");
$user mysql_fetch_array($getuser); 
echo 
"<form action='editprofile.php?update' method='post'>
<fieldset style='width: 350'>
Email: <input type='text' name='email' size='30' maxlength='55' value='
$user[email]'><br>
Location: <input type='text' name='location' size='30' maxlength='40' value='
$user[location]'><br>
Age: <input type='text' name='age' size='3' maxlength='3' value='
$user[age]'><br>
Sex: <select size='1' name='sex' value='
$user[sex]'>
<option value='Male' "
; if($user[sex] == Male) { 
echo 
"selected"; } 
echo 
">Male</option> 
<option value='Female' "
; if($user[sex] == Female) { 
echo 
"selected"; } 
echo 
">Female</option>
</select><br>
*yourfield*: <input type='text' name='*yourfield*' size='30' maxlength='40' value='
$user[*yourfield*]'><br>
<input type='submit' value='Update'>
</fieldset></form>"
;
}
}
else
{
echo 
"You are not logged in.";
}
echo 
"<center>";
?>

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