Forgot Password / Register
Site Statistics
Total Members: 520
Total Tutorials: 242
Newsest User: 8884244477
Todays Unique Hits: 562
0 Users 5 Guests Online
Forum Index » PHP + MySQL » Hide Email
Posted on Saturday 2nd June 2007 at 12:49 AM
MCP
templates/default/images/noavatar.png's Avatar
Junior Member
Ok Here is the problem. Imputting all the changes as shown on the 'Hide Email' tutorial. But the only problem I have is it does not update the DB. Example. Once I put it on I changed the default (via phpMyAdmin) to yes. Then I went to editprofile.php and chose it to say no. Updated the profile and went back to members.php and it does not hide it. Nor does it show no selected on editprofile.php

Below are the codes.

Members.php
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
include('config.php');

// Query database
$count_sql 'SELECT * FROM members';
$count_result mysql_query($count_sql);

//gets the number
$count mysql_num_rows($count_result);

$new mysql_fetch_array(mysql_query("SELECT * FROM `members` ORDER BY `id` DESC LIMIT 0, 1")); // Gets the newest member
echo "<strong>Newest member:</strong> " $new[username]; // displays the newest member
?>  <br>
<br>
  <?php
session_start
(); //allows session
include "config.php";
echo 
"<left>";
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 
"
<b>
$user[username]'s Profile</b><br><br>
<b>Email:</b> 
$user[email]<br>
<b>Location:</b> 
$user[location]<br>
<b>Sex:</b> 
$user[sex]<br>
<b>Age:</b> 
$user[age]<br>
<b>About:</b> 
$user[about]<br>
<b>Interests:</b> 
$user[interests]<br>
<b>MSN:</b> 
$user[msn]<br>
<b>Skype:</b> 
$user[skype]<br>
<b>AIM:</b> 
$user[aim]<br>
<b>deviantART:</b> 
$user[deviantart]<br>
<b>Yahoo:</b> 
$user[yahoo]<br>
"
;
$user_rank change_levels($user[userlevel]); //change level

}
}
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 
"<left>";
?>


Editprofile.php
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
session_start
(); //allows session
include "config.php";
echo 
"<left>";
//checks see if there logged in
if($logged[id]) 

if(isset(
$_GET['update'])){
$email addslashes(htmlspecialchars($_POST[email])); 
$ehidden htmlspecialchars($_POST[ehidden]); 
$location addslashes(htmlspecialchars($_POST[location])); 
$age = (int)addslashes(htmlspecialchars($_POST[age])); 
$sex addslashes(htmlspecialchars($_POST[sex])); 
$about addslashes(htmlspecialchars($_POST[about])); 
$interests addslashes(htmlspecialchars($_POST[interests])); 
$msn addslashes(htmlspecialchars($_POST[msn])); 
$skype addslashes(htmlspecialchars($_POST[skype])); 
$aim addslashes(htmlspecialchars($_POST[aim])); 
$deviantart addslashes(htmlspecialchars($_POST[deviantart])); 
$yahoo addslashes(htmlspecialchars($_POST[yahoo])); 
//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', `age` = '$age', location = '$location', ehidden = '$ehidden', `about` = '$about', `interests` = '$interests', `msn` = '$msn', `skype` = '$skype', `aim` = '$aim', `yahoo` = '$yahoo', `deviantart` = '$deviantart' WHERE `username` = '$logged[username]'");
echo 
"Profile updated!<br>
<a href=\"login.php\">Return to Member Area</a> or <a href=\"editprofile.php\">Continue Editing</a>"
;
}
//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'> 
<table width='350'>
  <tr>
    <td width='150'>Email:</td>
    <td width='200'><input type='text' name='email' size='30' maxlength='55' value='
$user[email]'></td>
  </tr>
  <tr>
    <td>Show Email?</td>
    <td><select name='ehidden'>
<option selected='selected' value='yes'>Yes</option>
<option value='no'>No</option>
</select></td>
  </tr>
  <tr>
    <td>Location:</td>
    <td><input type='text' name='location' size='30' maxlength='40' value='
$user[location]'></td>
  </tr>
  <tr>
    <td>Age:</td>
    <td><input type='text' name='age' size='3' maxlength='3' value='
$user[age]'></td>
  </tr>
  <tr>
    <td>Sex:</td>
    <td><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></td>
  </tr>
  <tr>
    <td>About:</td>
    <td><textarea name='about' cols='23.5' rows='7' maxlength='700' >
$user[about]</textarea></td>
  </tr>
  <tr>
    <td>Interests:</td>
    <td><input type='text' name='interests' size='30' maxlength='40' value='
$user[interests]' /></td>
  </tr>
  <tr>
    <td>MSN:</td>
    <td><input type='text' name='msn' size='30' maxlength='40' value='
$user[msn]' /></td>
  </tr>
  <tr>
    <td>Skype:</td>
    <td><input type='text' name='skype' size='30' maxlength='40' value='
$user[skype]' /></td>
  </tr>
  <tr>
    <td>AIM:</td>
    <td><input type='text' name='aim' size='30' maxlength='40' value='
$user[aim]' /></td>
  </tr>
  <tr>
    <td>deviantART:</td>
    <td><input type='text' name='deviantart' size='30' maxlength='40' value='
$user[deviantart]' /></td>
  </tr>
  <tr>
    <td>Yahoo:</td>
    <td><input type='text' name='yahoo' size='30' maxlength='40' value='
$user[yahoo]' /></td>
  </tr>
  
  <tr>
    <td colspan='2'><left>
        <input type='submit' value='Update'>
    </left></td>
  </tr>
</table>
</form>"
;
}
}
else
{
echo 
"You are not logged in.";
}
echo 
"<left>";
?>


Also are the queries I ran and changed.
Original (from tut)
PHP Code
1
ALTER TABLE `members` ADD `ehidden` CHAR( 3 ) NOT NULL DEFAULT 'no';


Changed to
PHP Code
1
ALTER TABLE `members` ADD `ehidden` CHAR( 3 ) NOT NULL DEFAULT 'yes';


Any help is appreciated.
Posted on Sunday 3rd June 2007 at 04:36 PM
ShadowMage
templates/default/images/noavatar.png's Avatar
Senior Member
Try This.
Find:
Code

<b>Email:</b> $user[email]<br>


Replace With:
Code

";
if($user[ehidden] == "yes"){
echo "<i>Hidden</i><br />";
}else{
echo "$user[email]";
}
echo "
Posted on Sunday 3rd June 2007 at 06:39 PM
MCP
templates/default/images/noavatar.png's Avatar
Junior Member
I think I fixed the members page. The problem I am having now is the DB is not being updated.

All the page codes are the same except for the members page. Which has been corrected with what was stated in the comment right above this one.
Posted on Sunday 3rd June 2007 at 08:51 PM
SkillMaster
templates/default/images/noavatar.png's Avatar
Senior Member
try this.
editprofile.php
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
session_start
(); //allows session
include "config.php";
if(
$logged[id]) 

switch(
$_GET[page])
{
default:
$fetch mysql_query("SELECT * FROM `members` WHERE `username` = '$logged[username]'");
$user mysql_fetch_array($fetch); 
echo (
"<form action='editprofile.php?update' method='post'> 
<table width='350'>
<tr>
<td width='150'>Email:</td>
<td width='200'><input type='text' name='email' size='30' maxlength='55' value='
$user[email]'></td>
</tr>
<tr>
<td>Show Email?</td>
<td><select name='ehidden'>
<option selected='selected' value='yes'>Yes</option>
<option value='no'>No</option>
</select></td>
</tr>
<tr>
<td>Location:</td>
<td><input type='text' name='location' size='30' maxlength='40' value='
$user[location]'></td>
</tr>
<tr>
<td>Age:</td>
<td><input type='text' name='age' size='3' maxlength='3' value='
$user[age]'></td>
</tr>
<tr>
<td>Sex:</td>
<td><input type='radio' value='male' name='sex'> Male<br>
<input type='radio' value='female' name='sex'> Female</td>
</tr>
<tr>
<td>About:</td>
<td><textarea name='about' cols='23.5' rows='7' maxlength='700' >
$user[about]</textarea></td>
</tr>
<tr>
<td>Interests:</td>
<td><input type='text' name='interests' size='30' maxlength='40' value='
$user[interests]' /></td>
</tr>
<tr>
<td>MSN:</td>
<td><input type='text' name='msn' size='30' maxlength='40' value='
$user[msn]' /></td>
</tr>
<tr>
<td>Skype:</td>
<td><input type='text' name='skype' size='30' maxlength='40' value='
$user[skype]' /></td>
</tr>
<tr>
<td>AIM:</td>
<td><input type='text' name='aim' size='30' maxlength='40' value='
$user[aim]' /></td>
</tr>
<tr>
<td>deviantART:</td>
<td><input type='text' name='deviantart' size='30' maxlength='40' value='
$user[deviantart]' /></td>
</tr>
<tr>
<td>Yahoo:</td>
<td><input type='text' name='yahoo' size='30' maxlength='40' value='
$user[yahoo]' /></td>
</tr>
<tr>
<td colspan='2'><left>
<input type='submit' value='Update'>
</left></td>
</tr>
</table>
</form>"
);
break;

case 
'update':
$email addslashes(htmlspecialchars($_POST[email])); 
$ehidden htmlspecialchars($_POST[ehidden]); 
$location addslashes(htmlspecialchars($_POST[location])); 
$age = (int)addslashes(htmlspecialchars($_POST[age])); 
$sex addslashes(htmlspecialchars($_POST[sex])); 
$about addslashes(htmlspecialchars($_POST[about])); 
$interests addslashes(htmlspecialchars($_POST[interests])); 
$msn addslashes(htmlspecialchars($_POST[msn])); 
$skype addslashes(htmlspecialchars($_POST[skype])); 
$aim addslashes(htmlspecialchars($_POST[aim])); 
$deviantart addslashes(htmlspecialchars($_POST[deviantart])); 
$yahoo addslashes(htmlspecialchars($_POST[yahoo])); 

if(
$sex == Male || $sex == Female)
{
$update mysql_query("UPDATE `members` SET `email` = '$email', `sex` = '$sex', `age` = '$age', location = '$location', ehidden = '$ehidden', `about` = '$about', `interests` = '$interests', `msn` = '$msn', `skype` = '$skype', `aim` = '$aim', `yahoo` = '$yahoo', `deviantart` = '$deviantart' WHERE `username` = '$logged[username]'");
echo (
"Profile updated!<br>
<a href='login.php'>Return to Member Area</a> or <a href='editprofile.php'>Continue Editing</a>"
);
}
else
(
echo (
"Please select a gender. <a href='editprofile.php'>Go back</a>");
}
break;
}
}
?>
Posted on Sunday 3rd June 2007 at 11:09 PM
MCP
templates/default/images/noavatar.png's Avatar
Junior Member
It's a blank page. What all did you change anyways?
Posted on Monday 4th June 2007 at 08:47 PM
SkillMaster
templates/default/images/noavatar.png's Avatar
Senior Member
Are you sure you're logged in because all these codes seem fine.
Posted on Monday 4th June 2007 at 08:52 PM
SkillMaster
templates/default/images/noavatar.png's Avatar
Senior Member
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
session_start
(); //allows session
include "config.php";
if(
$logged[id]) 

switch(
$_GET[page])
{
default:
$fetch mysql_query("SELECT * FROM `members` WHERE `username` = '$logged[username]'");
$user mysql_fetch_array($fetch); 
echo (
"<form action='?page=update' method='post'> 
<table width='350'>
<tr>
<td width='150'>Email:</td>
<td width='200'><input type='text' name='email' size='30' maxlength='55' value='
$user[email]'></td>
</tr>
<tr>
<td>Show Email?</td>
<td><select name='ehidden'>
<option selected='selected' value='yes'>Yes</option>
<option value='no'>No</option>
</select></td>
</tr>
<tr>
<td>Location:</td>
<td><input type='text' name='location' size='30' maxlength='40' value='
$user[location]'></td>
</tr>
<tr>
<td>Age:</td>
<td><input type='text' name='age' size='3' maxlength='3' value='
$user[age]'></td>
</tr>
<tr>
<td>Sex:</td>
<td><input type='radio' value='Male' name='sex'> Male<br>
<input type='radio' value='Female' name='sex'> Female</td>
</tr>
<tr>
<td>About:</td>
<td><textarea name='about' cols='23.5' rows='7' maxlength='700' >
$user[about]</textarea></td>
</tr>
<tr>
<td>Interests:</td>
<td><input type='text' name='interests' size='30' maxlength='40' value='
$user[interests]' /></td>
</tr>
<tr>
<td>MSN:</td>
<td><input type='text' name='msn' size='30' maxlength='40' value='
$user[msn]' /></td>
</tr>
<tr>
<td>Skype:</td>
<td><input type='text' name='skype' size='30' maxlength='40' value='
$user[skype]' /></td>
</tr>
<tr>
<td>AIM:</td>
<td><input type='text' name='aim' size='30' maxlength='40' value='
$user[aim]' /></td>
</tr>
<tr>
<td>deviantART:</td>
<td><input type='text' name='deviantart' size='30' maxlength='40' value='
$user[deviantart]' /></td>
</tr>
<tr>
<td>Yahoo:</td>
<td><input type='text' name='yahoo' size='30' maxlength='40' value='
$user[yahoo]' /></td>
</tr>
<tr>
<td colspan='2'><left>
<input type='submit' value='Update'>
</left></td>
</tr>
</table>
</form>"
);
break;

case 
'update':
$email addslashes(htmlspecialchars($_POST[email])); 
$ehidden htmlspecialchars($_POST[ehidden]); 
$location addslashes(htmlspecialchars($_POST[location])); 
$age addslashes(htmlspecialchars($_POST[age])); 
$sex addslashes(htmlspecialchars($_POST[sex])); 
$about addslashes(htmlspecialchars($_POST[about])); 
$interests addslashes(htmlspecialchars($_POST[interests])); 
$msn addslashes(htmlspecialchars($_POST[msn])); 
$skype addslashes(htmlspecialchars($_POST[skype])); 
$aim addslashes(htmlspecialchars($_POST[aim])); 
$deviantart addslashes(htmlspecialchars($_POST[deviantart])); 
$yahoo addslashes(htmlspecialchars($_POST[yahoo])); 


if(
$sex == "Male" || $sex == Female)
{
$update mysql_query("UPDATE `members` SET `email` = '$email', `sex` = '$sex', `age` = '$age', location = '$location', ehidden = '$ehidden', `about` = '$about', `interests` = '$interests', `msn` = '$msn', `skype` = '$skype', `aim` = '$aim', `yahoo` = '$yahoo', `deviantart` = '$deviantart' WHERE `username` = '$logged[username]'");
echo (
"Profile updated!<br>
<a href='login.php'>Return to Member Area</a> or <a href='editprofile.php'>Continue Editing</a>"
);
}
else
{
echo (
"Please select a gender. <a href='editprofile.php'>Go back</a>");
}
break;
}
}
?>

This works its tested.
Posted on Tuesday 5th June 2007 at 01:19 AM
MCP
templates/default/images/noavatar.png's Avatar
Junior Member
No it doesn't.

The problem with this is it still is not updating the DB with hidden or not. The other problem is once you have selected your gender it updates but go back to edit neither are selected. Which means people are going to have to update their gender every time they edit their profile.
Posted on Tuesday 5th June 2007 at 05:28 AM
SkillMaster
templates/default/images/noavatar.png's Avatar
Senior Member
change
PHP Code
1
2
3
4
<td>Sex:</td>
<td><input type='radio' value='Male' name='sex'> Male<br>
<input type='radio' value='Female' name='sex'> Female</td>

to
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
if ($logged[sex] == Male)
{
echo ("<td>Sex:</td>
<td><input type='radio' checked='checked' value='Male' name='sex'> Male<br>
<input type='radio' value='Female' name='sex'> Female</td>");
}
else
{echo ("<td>Sex:</td>
<td><input type='radio' value='Male' name='sex'> Male<br>
<input type='radio' checked='checked' value='Female' name='sex'> Female</td>");
}
Posted on Tuesday 5th June 2007 at 05:32 AM
SkillMaster
templates/default/images/noavatar.png's Avatar
Senior Member
Change
PHP Code
1
2
$update = mysql_query("UPDATE `members` SET `email` = '$email', `sex` = '$sex', `age` = '$age', location = '$location', ehidden = '$ehidden', `about` = '$about', `interests` = '$interests', `msn` = '$msn', `skype` = '$skype', `aim` = '$aim', `yahoo` = '$yahoo', `deviantart` = '$deviantart' WHERE `username` = '$logged[username]'");

to
PHP Code
1
2
$update = mysql_query("UPDATE `members` SET `email` = '$email', `sex` = '$sex', `age` = '$age', `location` = '$location', `ehidden` = '$ehidden', `about` = '$about', `interests` = '$interests', `msn` = '$msn', `skype` = '$skype', `aim` = '$aim', `yahoo` = '$yahoo', `deviantart` = '$deviantart' WHERE `username` = '$logged[username]'");