Jump to content

Recommended Posts

Hi all, I have a big big ask!

 

I was wondering if one of you could write me some code that does what I want so I can learn from seeing and changing as im stuck.

 

Basically I want to know how to make a site where users have profiles. I think I know what I need but I am at a loss of how to do it.

 

This just has to be the bare basics, as I just want pointing in the right direction.

 

Basically, say I have a table which includes the following:

 

id, username, password, age

 

what I want is a script which, when the user has logged in(i have got a basic reg/login script for this) they should be taken to say user_home.php which will allow them to edit there page (i dont need someone to write all this, just say, for it to let them change there age, I dont expect you to do everything!) Now say I have to users in the database and user 1 wants to see user 2's profile (just there age will do!) which I would like something like profile.php?user=users username.

 

Has anyone got the time and patience to do this for me?

 

Many many thanks

Link to comment
https://forums.phpfreaks.com/topic/152654-who-is-feeling-extremely-kind-today/
Share on other sites

I'm pretty new to PHP, but I figured I might as well help out other people where I can until my own question is answered.

 

I made profiles for my own site recently so I can supply you my code. It may not be pretty but it's working for me. I hope it is of any use for you.

 

Viewing/editing own profile:

<?php
session_start();
?>
<html>
<head>
<title>SQO Stellar Search Database</title>

<body>
<style>
input.submit {
display: inline; 
text-decoration: none; 
background: none; 
border: none;
}
input.submit:hover {
text-decoration: underline;
}
</style>
</head>


<?php
include("mysqlconnect.php");
$gb=$_SESSION['gb'];
$edit=$_POST['edit'];
$login = mysql_query("SELECT * FROM gebruikers WHERE gebruikersnaam='".$gb."'");
$results = mysql_num_rows($login); 
$gebr = mysql_fetch_array($login);
$admin=$gebr[admin];
if ($results==1){
include("menu.php");}
else
{include("menu2.php");}

if ($results==1 && $edit==0){
echo "<div id='content'>";
echo "<H3><B>Profile:</B></H3> ";
echo "<B>Username:</B> ";
echo "$gb<BR>"; 
echo "<B>SQO name:</B> ";
echo "$gebr[sqoname] <BR>"; 
echo "<B>Email:</B> ";
echo "$gebr[email]<BR>";
echo "<B>Status:</B> ";
if ($gebr[admin]==0){echo "Member <BR>";}
if ($gebr[admin]==1){echo "Site Moderator <BR>";}
if ($gebr[admin]==2){echo "Site Administrator <BR>";}
echo "<B>Systems uploaded:</B> ";
echo "$gebr[aantalsystems] <BR>"; 
echo "<B>Joined:</B> ";
echo date("d F Y",$gebr[registerdate]); 
echo "<BR><BR>";
?><FORM METHOD="post" ACTION="profile.php" style="display:inline; margin-top:0px; margin-bottom:0px"><INPUT name="gb" type="hidden" <?PHP echo "VALUE='$gebr[gebruikersnaam]'";?>> <INPUT name="edit" type="hidden" <?PHP echo "VALUE='1'";?> >
<input type=image name="formEditProfileSubmit" src="edit.jpg" <?php echo" alt='Edit profile data'"; ?> value="Bewerk" /> </FORM>
<?php
echo "</div>";
}
elseif ($results==1 && $edit==1){
echo "<div id='content'>";
echo "<H3><B>Profile:</B></H3> ";
?><FORM METHOD="post" ACTION="changeprofile.php">
<?php echo "<B>Username:</B> ";
echo "$gb<BR>";
echo "<B>SQO name:</B> ";
echo "<Input name='sqoname' type=text value='$gebr[sqoname]' size=15> <BR>"; 
echo "<B>Email:</B> ";
echo "$gebr[email] <BR>";
echo "<B>Show email:</B> ";
if ($gebr[showemail]==0){echo "<input type='radio' name='showemail' value='1'> <font size='2'>Yes</font> &nbsp&nbsp&nbsp&nbsp&nbsp<input type='radio' name='showemail' value='0' checked> <font size='2'>No</font><BR>";}
if ($gebr[showemail]==1){echo "<input type='radio' name='showemail' value='1' checked> <font size='2'>Yes</font> &nbsp&nbsp&nbsp&nbsp&nbsp<input type='radio' name='showemail' value='0'> <font size='2'>No</font><BR>";}
echo "<B>Status:</B> ";
if ($gebr[admin]==0){echo "Member <BR>";}
if ($gebr[admin]==1){echo "Site Moderator <BR>";}
if ($gebr[admin]==2){echo "Site Administrator <BR>";}
echo "<B>Systems uploaded:</B> ";
echo "$gebr[aantalsystems] <BR>"; 
echo "<B>Joined:</B> ";
echo date("d F Y",$gebr[registerdate]);  
?><BR><BR><INPUT name="gb" type="hidden" <?PHP echo "VALUE='$gebr[gebruikersnaam]'";?>>
<INPUT TYPE="SUBMIT" VALUE="Update Profile">  </FORM><BR><BR><BR>


<FORM METHOD="post" ACTION="changepass.php">
<?php echo "<B>Old password:</B> ";
echo "<Input name='oldpass' type=password size=15> <BR>"; 
echo "<B>New password:</B> ";
echo "<Input name='newpass' type=password size=15> <BR>"; 
echo "<B>Retype new password:</B> ";
echo "<Input name='newpass2' type=password size=15> <BR>"; 
?><BR><INPUT name="gb" type="hidden" <?PHP echo "VALUE='$gebr[gebruikersnaam]'";?>>
<INPUT TYPE="SUBMIT" VALUE="Change Pass">  </FORM>


<?php
echo "</div>";
}

else {echo "<div id='content'>Unexpected error.</div>";}
mysql_close();
?>
</body>
</html>

 

Searching users profile:

<?php
session_start();
?>
<html>
<head>
<title>SQO Stellar Search Database</title>
</head>
<body>
<?php 
include("mysqlconnect.php");
$gb=$_SESSION['gb'];
$login = mysql_query("SELECT * FROM gebruikers WHERE gebruikersnaam='".$gb."'");
$results = mysql_num_rows($login); 
$gebr = mysql_fetch_array($login);
if ($results==0)
{
include("menu2.php");
echo '<div id="content">'; 
echo "Access to user info denied for Guests";
echo "</div>";
}
else
{  
include("menu.php");
echo '<div id="content">';
?>
<CENTER>
<h3><B>Search user</B></h3>
<form action="userinfo2.php" method="post">
<input type="hidden" value=<?php echo $gebr[gebruikersnaam]; ?> name="gb">
Search user:<br>
<input type="text" name="user"><br>

<br><input type="submit" value="Search"></form></center>
<?php echo "</div>";}
mysql_close();
?>
</body>
</html>

 

 

Displays users info entered in script above:

<?php
session_start();
?>
<html>
<head>
<title>SQO Stellar Search Database</title>

<body>
<style>
input.submit {
display: inline; 
text-decoration: none; 
background: none; 
border: none;
}
input.submit:hover {
text-decoration: underline;
}
</style>
</head>


<?php
include("mysqlconnect.php");
$gb=$_POST['gb'];
$user=$_POST['user'];
$login = mysql_query("SELECT * FROM gebruikers WHERE gebruikersnaam='".$gb."'");
$results = mysql_num_rows($login); 
$gebr = mysql_fetch_array($login);
$admin=$gebr[admin];

if ($results==1){
include("menu.php");
$retrieveuser = mysql_query("SELECT * FROM gebruikers WHERE gebruikersnaam='".$user."'");
$userfound = mysql_num_rows($retrieveuser); 
$userarray = mysql_fetch_array($retrieveuser);

if ($userfound==1){
echo "<div id='content'>";
echo "<H3><B>Profile:</B></H3> ";
echo "<B>Username:</B> ";
echo "$userarray[gebruikersnaam] <BR>"; 
echo "<B>SQO name:</B> ";
echo "$userarray[sqoname] <BR>"; 
echo "<B>Status:</B> ";
	if ($userarray[admin]==0){echo "Member <BR>";}
	if ($userarray[admin]==1){echo "Site Moderator <BR>";}
	if ($userarray[admin]==2){echo "Site Administrator <BR>";}
echo "<B>Email:</B> ";
	if ($userarray[showemail]==0){echo "<i>hidden</i> <BR>";}
	if ($userarray[showemail]==1){echo "$userarray[email] <BR>";}
echo "<B>Systems uploaded:</B> ";
echo "$userarray[aantalsystems] <BR>"; 
echo "<B>Joined:</B> ";
echo date("d F Y",$userarray[registerdate]);  


	if ($gebr[admin]==2){
	echo "<BR><BR><BR><B>Admin control panel: </B><BR>";

	if ($userarray[admin]==0){
	?><img src='makemembergray.png' alt='Reset Special Privilages'>
<FORM METHOD="post" ACTION="addmodadmin.php" style="display:inline; margin-top:0px; margin-bottom:0px;"><INPUT name="gb" type="hidden" <?PHP echo "VALUE='$gebr[gebruikersnaam]'";?>><INPUT name="user" type="hidden" <?PHP echo "VALUE='$userarray[gebruikersnaam]'";?>><INPUT name="admin" type="hidden" <?PHP echo "VALUE='1'";?>>
	<input type=image name="formEditProfileSubmit" src="addmod.png" <?php echo" alt='Give Moderator Status'";?> value="Bewerk" /></FORM>
	<FORM METHOD="post" ACTION="addmodadmin.php" style="display:inline; margin-top:0px; margin-bottom:0px;"><INPUT name="gb" type="hidden" <?PHP echo "VALUE='$gebr[gebruikersnaam]'";?>><INPUT name="user" type="hidden" <?PHP echo "VALUE='$userarray[gebruikersnaam]'";?>><INPUT name="admin" type="hidden" <?PHP echo "VALUE='2'";?>>
	<input type=image name="formEditProfileSubmit" src="addadmin.png" <?php echo" alt='Give Admin Status'";?> value="Bewerk" /></FORM>
	<?php
	}
	if ($userarray[admin]==1){
	?><FORM METHOD="post" ACTION="addmodadmin.php" style="display:inline; margin-top:0px; margin-bottom:0px;"><INPUT name="gb" type="hidden" <?PHP echo "VALUE='$gebr[gebruikersnaam]'";?>><INPUT name="user" type="hidden" <?PHP echo "VALUE='$userarray[gebruikersnaam]'";?>><INPUT name="admin" type="hidden" <?PHP echo "VALUE='0'";?>>
	<input type=image name="formEditProfileSubmit" src="makemember.png" <?php echo" alt='Reset Special Privilages'";?> value="Bewerk" /></FORM>
&nbsp<img src='addmodgray.png' alt='Give Moderator Status'>		
<FORM METHOD="post" ACTION="addmodadmin.php" style="display:inline; margin-top:0px; margin-bottom:0px;"><INPUT name="gb" type="hidden" <?PHP echo "VALUE='$gebr[gebruikersnaam]'";?>><INPUT name="user" type="hidden" <?PHP echo "VALUE='$userarray[gebruikersnaam]'";?>><INPUT name="admin" type="hidden" <?PHP echo "VALUE='2'";?>>
	<input type=image name="formEditProfileSubmit" src="addadmin.png" <?php echo" alt='Give Admin Status'";?> value="Bewerk" /></FORM>
	<?php
	}
	if ($userarray[admin]==2){
	?><FORM METHOD="post" ACTION="addmodadmin.php" style="display:inline; margin-top:0px; margin-bottom:0px;"><INPUT name="gb" type="hidden" <?PHP echo "VALUE='$gebr[gebruikersnaam]'";?>><INPUT name="user" type="hidden" <?PHP echo "VALUE='$userarray[gebruikersnaam]'";?>><INPUT name="admin" type="hidden" <?PHP echo "VALUE='0'";?>>
	<input type=image name="formEditProfileSubmit" src="makemember.png" <?php echo "alt='Reset Special Privilages'";?> value="Bewerk"></FORM>
	<FORM METHOD="post" ACTION="addmodadmin.php" style="display:inline; margin-top:0px; margin-bottom:0px;"><INPUT name="gb" type="hidden" <?PHP echo "VALUE='$gebr[gebruikersnaam]'";?>><INPUT name="user" type="hidden" <?PHP echo "VALUE='$userarray[gebruikersnaam]'";?>><INPUT name="admin" type="hidden" <?PHP echo "VALUE='1'";?>>
	<input type=image name="formEditProfileSubmit" src="addmod.png" <?php echo "alt='Give Moderator Status'";?> value="Bewerk"></FORM>
	&nbsp<img src='addadmingray.png' alt='Give Admin Status'><?php

	}

?><FORM METHOD="post" ACTION="resetpass.php" style="display:inline; margin-top:0px; margin-bottom:0px;"><INPUT name="gb" type="hidden" <?PHP echo "VALUE='$gebr[gebruikersnaam]'";?>><INPUT name="user" type="hidden" <?PHP echo "VALUE='$userarray[gebruikersnaam]'";?>>
		<input type=image name="formEditProfileSubmit" src="resetpass.png" <?php echo" alt='Reset Password to 12345'"; ?> value="Bewerk" /></FORM><?php
}

if ($gebr[admin]==1 && $userarray[admin]==0)
{
	echo "<BR><BR><BR><B>Admin control panel: </B><BR>";
?><FORM METHOD="post" ACTION="resetpass.php" style="display:inline; margin-top:0px; margin-bottom:0px;"><INPUT name="gb" type="hidden" <?PHP echo "VALUE='$gebr[gebruikersnaam]'";?>> <INPUT name="user" type="hidden" <?PHP echo "VALUE='$userarray[gebruikersnaam]'";?> >
		<input type=image name="formEditProfileSubmit" src="resetpass.png" <?php echo" alt='Reset Password to 12345'"; ?> value="Bewerk" /> </FORM>
<?php
}
}

else {echo '<div id="content">';
echo "User $user does not excist.";
echo "</div>";
}

}
else
{include("menu2.php");
echo '<div id="content">';
echo "Please <a href='login.php'>log in</a> to your SQOSSD account first. <BR><BR> Or if you don't have an account yet <a href='regist er.php'>register now</A>.";
echo "</div>";
}

?>
</body>
</html>

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.