Page 1 of 1

Text Based Mafia Game || View/Edit Profile and Find Player Part 6 Create a View player profile , edit profile and Find player. Rate Topic: -----

#1 Denis1  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 32
  • View blog
  • Posts: 103
  • Joined: 29-July 09

Posted 20 August 2010 - 03:34 PM

Hey there check out my other tutorials before jumping in to this one.

Now that we are getting many files at the begin of every tutorial i am going to list the name of the files we are going to be using and creating.
Files We are going to use
  • Safe.php
  • Usersonline.php
  • Left.php


Files We are going to create
  • Config.php
  • View_Profile.php
  • Edit_Profile.php
  • Find_Player.php


View_Profile.php
We are going to look in to creating profiles for users to have a little profile about themselves and it will display an user basic information like rank / wealth status.

We are going to do things a bit different today. I am going attach View_Profile.php. The reason being that its gets confusing really quick. So click and download View_Profile.php.Attached File  View_Profile.php (4.78K)
Number of downloads: 459
I am still going to explain it and there are comment in the coding to help you understand what i am taking about.

After downloading the file. Adds this field under your mysql users table.
profile text NOT NULL,


That field holds the information of the content on the users profile (We will get to that later).

The way the View_Profile works is different to any other page you will be creating. There will be no direct link to View_Profile.php, This is because If you do get to View_profile.php it will be blank because it dont know what users profile to get information from. This is way we are going to use the
$_GET
Function in php. The URL of the View profile will be in the format "www.example.com/View_Profile.php?name=Denis". the "?name=" is going to carry the name of the user who will want to get information on. So we use the $_Get function to get it.

How the $_Get function works. The Function is written like this
"$_GET['name'] "
The [name] part referrers to the "name" in the browser. The Get function gets the data from the URL link provided. So whatever is at the end of the "=" we are going to get and search for in the database. If you dont understand the Get function please read more on it from the PHP Manuel.


If you try to run View_profile.php you will get errors Follow the steps below to avoid these errors.

THIS PART IS VERY IMPORTANT, PLEASE MAKE SURE YOU UNDERSTAND THIS AND CARRY OUT THE STEPS BECAUSE THIS IS THE BACKBONE OF YOUR GAME.

You might be wondering how we are going to do out ranks and wealth ranks etc. We are going to create a file called Config.php

On Safe.php we are going to add new arrays that are going to hold Important Information. These informations are in arrays and they are :-
  • Cars
  • Cars value
  • Location
  • Ranks
  • Wealth Ranks
  • Weapons (Gun)
  • Weapons price
  • Protection
  • Protection price

These are the arrays that we are going to add to safe.php. Open Safe.php and add the array below.
$car_park = array ("Daewoo Nexia", "Renault Safrane", "Cadillac Seville STS", "Fiat Marea", "Rover 100", "Ferrari 599 GTB Fiorano ", "Mercedes-Benz SLR McLaren ", "Bugatti EB Veyron"); 

$car_value = array ("200", "400", "500", "700", "800", "900", "1100", "1200","1500", "1500", "1700", "2000", "3000", "4000", "4500", "5000");

$location_array = array("Avalanche", "England", "Italy", "Iraq", "France", "U.S.A", "Sierra Leone", "Spain", "China", "Mars");

$rank_array = array("Tramp.", "Pikey.", "Goon.", "Thug.", "Gangster.", "Terrorist.", "Gang Leader.", "Hustler.", "Capo.", "Under Boss.", "Boss.", "WarLord.", "Godfather.", "God Of War.", "Emperor.", "Sovereign.", "Admin/Coder.", "Moderator.", "Owner.", "Admin");

$rank_exp_array = array("51", "151", "301", "801", "2501", "5501", "9001", "16001", "25001", "36001", "50001", "75001", "110001", "150001", "300001");

$gun_array = array("Armed less.", "Colt Derringer.", "Smith & Wesson.", "Colt SAA.", "Winchester.", "Shotgun.", "Thompson.", "Machine Gun.");

$gun_cost_array = array("50000", "150000", "200000", "500000", "1000000", "200", "500");

$protection_array = array("None.", "Guard Dog.", "Trained Guard Dog.", "Armed Escort.", "2 Armed Escorts.", "Reinforced Pontiac.", "armored Ford T.", "Armored Duesenberg.");

$protection_cost_array = array("50000", "150000", "350000", "550000", "1500000", "200", "500");

$wealth_array = array("Broke.", "Penny less.", "very Poor.", "Poor.", "Eaner.", "Wealthy.", "Rich.", "Extremely Rich.", "Millionaire.", "Multi Millionaire.", "Rich Millionaire.", "Crazy Millionaire.", "Insane Millionaire.", "Billionaire.", "Multi Billionaire.", "Admin Wealth.");


This is the fun part of the game creating ranks weapons etc etc. Please remember you can change these values to what suits your game best and you can add/remove to the list. In fact you should edit this list and add your own ranks cars and locations. Be imaginative explore things and be very creative.

Back to view profile. On view profile you can see that we used the rank and wealth rank arrays. Study them well because it is easy to use. We also use the staff arrays we made earlier so show is an user is an admin ,mod , or hdo.
Those are the mains things on View_profile.

If we are on users online and you want to click on an user to see their profile nothing happens. This is because for now it is like this
  echo "$online_name.";

Thats just echos the name of the members. For it to get to View Profile we need to echo it with the link to their profile, which is this.

   echo "<a href=\"View_Profile.php?name=". $online_name ."\" onfocus=\"if(this.blur)this.blur()\">".$online_name."</a>";


So go to Usersonline and Find "echo "$online_name.";" and replace with the code above.
If you did that right you should be able to click on your name and see your profile.

Edit_Profile.php
Now that we have profile we need to give people the tools to edit it.
Step One - HTML
The only thing that the player will be able to edit is the Quote which is under their information on their profile.
Create a page called Edit_profile.php and add the following.

<form id="form1" name="form1" method="post" action="">
<table width="90%" border="1" align="center" >
  <tr>
    <td align="left" >Quote:</td>
  </tr>
  <tr>
    <td align="center" ><textarea name="quote_box" cols="50" rows="10"  id="quote_box"/><?php echo htmlspecialchars(stripslashes($profile)); ?></textarea>
      </td>
  </tr>
  <tr>
    <td height="29" align="right" ><input name="Quote" type="submit"  id="Quote" value="Update Quote." onfocus="if(this.blur)this.blur()" /></td>
  </tr>
</table>

</form>



Step Two - Updating the database with the entry.
When user click on edit profile the should be able to see what is already there then edit it and save it.

On Safe.php Update the part where information are store on a player, like their name, and id. From line 15, with this
$sql = "SELECT * FROM users WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'";
$query = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_object($query);
$id = htmlspecialchars($row->id);
$userip = htmlspecialchars($row->userip);
$name = htmlspecialchars($row->name);
$sitestate = htmlspecialchars($row->sitestate);
$password = htmlspecialchars($row->password);
$mail = htmlspecialchars($row->mail);
$money = htmlspecialchars($row->money);
$exp = htmlspecialchars($row->exp);
$rank = htmlspecialchars($row->rank);
$health = htmlspecialchars($row->health);
$points = htmlspecialchars($row->points);
$profile = htmlspecialchars($row->profile);


Back on Edit_Profile add this simple php code to just update the profile on the database.
<? 
if(isset($_POST['Quote'])){
echo "Your quote has been updated.";

$result = mysql_query("UPDATE users SET profile='".mysql_real_escape_string($_POST['quote_box'])."' WHERE id='" .mysql_real_escape_string($_SESSION['user_id']). "'") 
or die(mysql_error());

$quote = $_POST['quote_box'];

}// update quote.

?>


that is all for Edit_Profile.php. It is very simple not much to it. It is kinda like the first part where we just updated the database with an information that we entered.

Find_Player.php
We need a way for player to look for other payers in side the game. So we are going to create a very simple search system.

Most of the php will be mixed with our html, so we are not going to be separating them.
Create a file Called Find_Player.php and add the following code
<form method="post">
  <?php if(!isset($_POST['Search'])){ ?>
  <table width="90%" border="1" >
  <tr>
    <td colspan="2" align="left" >Search Player: </td>
    </tr>
  <tr>
    <td width="50" align="left">Name: </td>
    <td width="300" align="center">
      <input name="player_name" type="text" id="player_name" style=' width: 95%; ' maxlength="20" /></td>
  </tr>
    <tr>
      <td colspan="2" align="right" background="../img/bg/test12.png" ><input name="Search" type="submit"  id="Search" value="Search." onfocus="if(this.blur)this.blur()"/></td>
    </tr>
</table>
<?php 

}// searchbox.

$_POST['player_name'] = trim($_POST['player_name']);

if(isset($_POST['Search'])){

if(empty($_POST['player_name'])){ 
echo "Empty search field.";
} else {

if (strlen($_POST['player_name']) > "20"){
echo "The username may not consist out of more then 20 characters.";
}else{

if (ereg('[^A-Za-z0-9]', $_POST['player_name'])) {
echo "Invalid Name only A-Z,a-z and 0-9 is allowed.";
}else{
	
$result = mysql_query("SELECT name FROM users
WHERE name LIKE '".mysql_real_escape_string($_POST['player_name'])."' ORDER BY name ASC") or die(mysql_error());
	
if (mysql_num_rows($result) == 0){		
echo "There is no player with that name.";
}else {
?>
<br />
    <table width="250" border="1" align="center" >
  
  <tr>
    <td align="left" >Results:</td>
    </tr>
  <tr>
    <td align="center">Name:</td>
    </tr>
  	<?php while($row = mysql_fetch_array( $result )) { ?>
  <tr>
    <td align="center"><label><?php echo "<a href=\"View_Profile.php?name=". $row['name'] ."\" onfocus=\"if(this.blur)this.blur()\">" . $row['name'] . "</a>"; ?></label></td>
    </tr>
 <?php  }// while loop ?>
</table>
  <?php
}
}
} 
}
}
?>
</form>


This is a very simple search code. All it does is search the database table "users" under name and it will display the result of all the members that fit under the condition.
If a result is found it will display name and rank. You can modify the content to your liking.

If you dont understand anything from this part or you see any mistake or grammar errors or coding error/improvement please post below, thank you.

If your code is not working

If your code is not working dont worry we all make mistakes. Here is a list of things you should check are completed. :-
  • Check and make sure you have the Right Field names in your php for example if the name of your button is called "Submit" make sure when you are referring to it on your php code make sure you type "Submit"
  • If your are clicking on a button, and nothing is happening you need a form field around the html. <form method="post"></form>
  • If you are getting lots of connection errors it is because you dont have your left and right included on the page. Remember on every page includes your left and right, like this<? require("Left.php"); ?> <? require("Right.php"); ?>. Please remember that <? require("Left.php"); ?> needs to be before any html on the page and it needs to be online one

If your error is not on there please post it below and i will be happy to help you

That is it for today tutorial. In the next tutorial we are going to look at improving our Right and left Menus and we are going to create a simple Help Desk where users can ask questions for your HDOs to answer. See you then.


--------
Mod: the code can be found here:
https://github.com/m...ext_Based_Mafia


Is This A Good Question/Topic? 1
  • +

Replies To: Text Based Mafia Game || View/Edit Profile and Find Player Part 6

#2 IrisBlaze  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 29-August 10

Posted 29 August 2010 - 02:35 PM

why not link to the other 5 parts?
Was This Post Helpful? 0
  • +
  • -

#3 Easyslider01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 20-September 11

Posted 25 October 2011 - 12:49 AM

For some reason my right.php will not show up and it says I need to connect to a database every time I'm on my Useronline.php.

Here is my code:
<?php require("left.php"); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Users Online</title>
</head>

<body>

<table width="90%" height="94" border="1">
	<tr>
    	<td height="23" align="center">Users Online</td>
    </tr>
    <tr>
    	<td>
		<?php 
		
		$sql = "SELECT name FROM users WHERE DATE_SUB(NOW(), INTERVAL 5 MINUTES) <= lastactive ORDER BY id ASC";
		$query = mysql_query($sql) or die(mysql_error());
		$count = mysql_num_rows($query);
		$i = 1;
		while($row = mysql_fetch_object($query)) {
			
			$online_name = htmlspecialchars($row->name);
			
			echo "<a href=\"View_Profile.php?name=".$online_name."\"onfocus=\"if(this.blur)this.blur()\">".$online_name."</a>";
			
			if($i != $count) {
				
				echo '<label>-</label>';	
				
			}
			$i++;
			
		}
		echo "<p><center>Total Online: ".$count."</center></p>";
		 
		
		?>
        </td>
    </tr>
</table>

</body>
</html>

<?php require("right.php"); ?>


Was This Post Helpful? 0
  • +
  • -

#4 Tractatio  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 06-November 12

Posted 06 November 2012 - 01:30 PM

Just for people who try this and can't get it to find players by just searching 1 letter. The reason this won't work is because the sql code doesn't allow it.

The code in question:
$result = mysql_query("SELECT username FROM Users
WHERE username LIKE '".mysql_real_escape_string($_POST['player_name'])."' ORDER BY username ASC") or die(mysql_error());


To fix this you need to add a % between the "' just before the ORDER like so
$result = mysql_query("SELECT username FROM Users
WHERE username LIKE '".mysql_real_escape_string($_POST['player_name'])."%' ORDER BY username ASC") or die(mysql_error());


Once done this like search the database for anything.
Was This Post Helpful? 1
  • +
  • -

#5 Teajay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-December 13

Posted 17 December 2013 - 03:13 PM

Does anyone have a copy of the attachments from this thread?
Was This Post Helpful? 0
  • +
  • -

#6 Denis1  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 32
  • View blog
  • Posts: 103
  • Joined: 29-July 09

Posted 27 December 2013 - 02:46 PM

I did this on an old pc lucky I still have that laying around, so over the next couple of day I will go hunting for those files and if nothing is found I will re-code them.
Was This Post Helpful? 0
  • +
  • -

#7 JRay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-January 14

Posted 23 January 2014 - 10:23 AM

How could I remove the protection and have it set up where players have a set amount of protection when they sign up?Would I just program it where it just puts them in protection when they sign up?
Was This Post Helpful? 0
  • +
  • -

#8 bamsetheking  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 16
  • Joined: 21-November 12

Posted 23 January 2014 - 08:29 PM

View PostJRay, on 23 January 2014 - 10:23 AM, said:

How could I remove the protection and have it set up where players have a set amount of protection when they sign up?Would I just program it where it just puts them in protection when they sign up?


do you even have a kill page?:)/>
Was This Post Helpful? 0
  • +
  • -

#9 JRay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-January 14

Posted 24 January 2014 - 07:28 AM

View Postbamsetheking, on 23 January 2014 - 08:29 PM, said:

View PostJRay, on 23 January 2014 - 10:23 AM, said:

How could I remove the protection and have it set up where players have a set amount of protection when they sign up?Would I just program it where it just puts them in protection when they sign up?


do you even have a kill page?:)/>/>


Right now I have started with the layout of the main page and im working on the login page.Im still new at this been learning HTML css java and PHP for the last few months trying to study up on as much as I can while giving my game a go.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1