• (3 Pages)
  • +
  • 1
  • 2
  • 3

Text Based Mafia Game || Database with Connection Part 1. Setting up a database with simple Connection Rate Topic: ***** 3 Votes

#1 Denis1  Icon User is offline

  • D.I.C Head
  • member icon

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

Posted 03 August 2010 - 05:06 PM

*
POPULAR

Online text based games are becoming increasingly popular amongst developers. These online games are what drove me to become a developer myself, I started developing in php five years ago when i was 12 and the reason i did was because of a text based game i played and i wanted to make one just like it. Over the years i have made over 5 different game scripts, Now i am just about an expert in php and looking back, the one thing that drove me crazy was there wasn't enough help when it came to text based games, i mean the structure of how to develop a game was there for you but the features you needed was not thought to you. You have to learn php and get yours working yourself. Now i am experienced and i have had my fun i am teaching my work to other developers who want to learn, in this 10 part tutorials i will be teaching you how to build a basic working text based game with PvP (Player versus Player) interaction.


I know there are other tutorials out there that has information on what you need to make a text based game but mine is different because it is a step by step guide in making a text based game.

BEFORE YOU START!!!. Make sure you have a good idea read THIS It is a good starting point

What you need to Know.
You need to know basic commands in PHP, HTML ,Mysql and CSS. Please refer to other tutorials in order to do so. You don't have to be an expert in-order to do these tutorials. Click here to learn the basic Html , php and css. that you will be needing.

Programmers you need
For this to work well you need a good HTML/PHP/CSS editor. I recommend Adobe Dreamwaver. I have being using dreamwaver ever since it was under micromedia.


Hosting
You need a very good host that support both php and mysql. if you are serious about doing this and hoping to get something back from it, pay for a host instead of using a free one. (Click here for a cheap host.) if you are looking.


Lets Begin
Ok at this point i am assuming that you know the basic php, html, and css and you have your host set up with a mysql database. if not please do so be for continuing because you will not understand what i am talking about until you do.


Step One - Connection to database.
I am using PHPMyAdmin on my host and i will be using it in this tutorial when i am showing screen shots.

Create a page called connect.php
// this is going to contain information that will connect the database to your site.

Fill out the connection page using the information on your host.

<? 
$mysql_server = "localhost"; // localhost is common on most hosts.

$mysql_user = "Denis1_DIC"; //  this is the name of your username of the server.

$mysql_password = "DICgame"; // the password connected to the username. MAKE IT COMPLEX.

$mysql_database = "Denis1_DIC_Game"; // the database name of where to connect to and where the information will be help.

$connection = mysql_connect("$mysql_server","$mysql_user","$mysql_password") or die ("Unable to establish a DB connection");

$db = mysql_select_db("$mysql_database") or die ("Unable to establish a DB connection");
?>




Step two - Setting up the database.
We need to set up the database to store information. This is the main IMPORTANT part of the whole game, Without information being saved you got no game. players wont be saved it will just be a php scripts with lots of errors. also we will check if the connection worked.

In the database you have created add a this table.
#
# Table structure for table `users`
#

CREATE TABLE users(
  id int(11) NOT NULL auto_increment,
  userip varchar(50) NOT NULL default '',
  signup_ip varchar(255) NOT NULL,
  login_count varchar(10) NOT NULL default '0',
  login_ip text NOT NULL,
  name varchar(50) NOT NULL default '',
  account_type char(1) NOT NULL default '1',
  password varchar(50) NOT NULL default '',
  sitestate char(1) NOT NULL default '0',
  signup varchar(255) NOT NULL default '',
  money varchar(20) NOT NULL default '1500',
  exp varchar(20) NOT NULL default '0',
  rank char(2) default '0',
  health char(3) NOT NULL default '100',
  points varchar(10) NOT NULL default '0',
  PRIMARY KEY  (id)
) ENGINE=MyISAM AUTO_INCREMENT=3023 DEFAULT CHARSET=latin1;
# --------------------------------------------------------

.

The code above contain all the information we need to create a base account for the game. You can add more if you see fit. Again please make sure you know the basic of mysql before trying to add / deleting tables.

The numbers in the ' ' at the end of every line are the values, like for money it is '1500' this mean that every data added will be assigned 1500 which means that the player will automatically start of with say £1500 (or what every currency you choose). You can see most defaults are '0' or '1' this is because we will use it later and we will change it and increase it values. Like for account type and exp(experience) etc etc.

Testing if the connection worked.

To test if the connection worked we are going to add data to the database and try to echo out some data. DONT WORRY AND DONT GET CONFUSED. THIS BIT HAS NOTHING TO DO WITH YOUR GAME. IT IS JUST TO CHECK AND SEE IF EVERYTHING UP TO THIS POINT IS CORRECTLY DONE.

Create a page call test.php
We are going to create a simple form that will add database to the table we have already created.

In the body part of the html on test.php add
<form id="form1" name="form1" method="post" action="">
  <p>
    <center>
      ENTER NAME <br />
      <input type="text" name="name" id="name" />
      <br />
      <input type="submit" name="Submit" id="Submit" value="Submit" />
    </center>
  </p>
</form>



this is just a simple html form that we are going to use to add data to the table.
i really wont be explaining the html bits because it is basic and i am assuming you know and understand html, if you dont back up and learn html.

Just above the html you have just added, add this
<? 
if (isset($_POST['Submit'])) {
$sql = "INSERT INTO users SET id = '', name = '".$_POST['name']."'";
$res = mysql_query($sql);

echo "".$_POST['name']." ADDED";
}
?>


This is the php code. this code will work when the Submit button is hit. Its add a new field and the fills out the name. the rest of the other fields will be fill with defaults.


For the connection to work you need to add this line above any html on test.php.
<?php include_once("connect.php"); ?>

that line includes the connect.php we made.

At this point test.php should look like this.
<?php include_once("connect.php"); ?>
<html >
<head>
<title>Test</title>
</head>

<body>


<? 
if (isset($_POST['Submit'])) {
$sql = "INSERT INTO users SET id = '', name = '".$_POST['name']."'";
$res = mysql_query($sql);

echo "".$_POST['name']." ADDED";
}
?>
<form id="form1" name="form1" method="post" action="">
  <p>
    <center>
      ENTER NAME <br />
      <input type="text" name="name" id="name" />
      <br />
      <input type="submit" name="Submit" id="Submit" value="Submit" />
    </center>
  </p>
</form>
</body>
</html>



Ok now if everything is done as described above you can now add data to the table "users", In-order to add data run the test.php in the browser and fill out the name bit and click submit the data will then be added to the table. See the screen shots below

Posted Image

Posted Image

Posted Image

Posted Image


Step Three - Updating and displaying data.
If all the above steps worked, it is now time to update some data and display them on our screen.

The following is a bit complex if you are just a beginner and if you only know the basic, But dont worry we will be going over this again soon in later parts and it will be fully explained

Replace the whole of test.php with this.
<?php include_once("connect.php"); ?>
<html >
<head>
<title>Test</title>
</head>

<body>


<? 
if (isset($_POST['Submit'])) {
$sql = "INSERT INTO users SET id = '', name = '".$_POST['name']."'";
$res = mysql_query($sql);

echo "".$_POST['name']." ADDED";
}


// This is the bit that is new .The line below is just selecting data from users table and adding it to result
$result = mysql_query("SELECT name,id,money FROM users ORDER BY id DESC") or die(mysql_error());


// this is assingint som html for the drop down menu along with the some php and the data from result
$member_list = "";
	while($row = mysql_fetch_array( $result )) {
		if($row['name'] == $_POST['Name_list']){
		$member_list .= "<option selected=\"selected\" value=\"".$row['name']."\">".$row['name']."</option>";
		}else{
		$member_list .= "<option value=\"".$row['name']."\">".$row['name']."</option>";		
		}
	}


// the following below happend when you hit search and what it does is select data on the name you clicked on from the menu.
if(isset($_POST['Select']) or isset($_POST['update'])){

$sql = "SELECT * FROM users WHERE name='".mysql_real_escape_string($_POST['Name_list'])."'";
$query = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_object($query);
$select_money = htmlspecialchars($row->money);
}

// Updating the database with the information entered.
if(isset($_POST['update'])){
$result = mysql_query("UPDATE users SET money='".mysql_real_escape_string($_POST['money'])."' WHERE name='" .mysql_real_escape_string($_POST['Name_list']). "'") 
or die(mysql_error());	

echo "".$_POST['Name_list']."'s money have been changed.";
}
?>
<form method="post" >
  <p>
  <center>
    <p>ENTER NAME <br />
        <input type="text" name="name" id="name" />
        <br />
        <input type="submit" name="Submit" id="Submit" value="Submit" />
    </p>
    <p><br>
      <span class="cell">
      Select a Name
      <select name="Name_list" class="textbox" id="Name_list">
        <option value="<?php echo htmlspecialchars($_GET['user']);?>">Select.</option>
        <?php echo $member_list; ?>
      </select>
      </span>
      <input type="submit" name="Select" id="Select" onfocus="if(this.blur)this.blur()" value="Select">
      <br>
Change the Money
<input type="text" name="money" id="money" value="<?php echo $select_money; ?>">
    <br>
    <input type="submit" name="update" id="update" value="Update">
    <br>
    </p>
    <p>&nbsp;</p>
    <table width="50%" border="2" cellspacing="1" cellpadding="0">
      <tr align="center">
        <td colspan="3">Users Information</td>
      </tr>
      <tr align="center">
        <td>ID</td>
        <td>Name</td>
        <td>Money</td>
      </tr>
      <? 
$result = mysql_query("SELECT * FROM users") or die(mysql_error());
// keeps getting the next row until there are no more to get
	while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table?>
      <tr>
       <td><label for="<?php echo $row['id']; ?>"><?php
	$name2=$row['id'];
	echo "$name2"; ?>
    </label></td>
        <td><? echo $row['name'] ?></td>
        <td><? echo $row['money'] ?></td>
      </tr>
        <?php }// while loop ?>
    </table>
    <p>&nbsp;</p>
  </center>
  </p>
</form>
</body>
</html>




I have added every thing in tables and i have add the forms we will be needing in-order to update the database and display data back. In-order for the data to be displayed on our screen you can php within the html.

I have added comments within the php to help explain what is going on.

With all that done you should be able to run your scripts and you should be able to select A name from the drop down menu and edit and update the money. you should then see the money displayed at the bottom in the table.


Thats about it for the first step. You now have the basics database connections and setup you need.

If you see any improvements, mistakes and grammar error in my codes please post it below i too want to learn new ways of doing things


In part 2 we are going to set up a really basic registration , login and a forgot password page.

Click Here for part 2


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

This post has been edited by modi123_1: 08 January 2014 - 09:02 PM


Is This A Good Question/Topic? 8
  • +

Replies To: Text Based Mafia Game || Database with Connection Part 1.

#2 Lightme  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 06-March 10

Posted 06 September 2010 - 11:40 AM

For me this code is not seeming to work correctly it get stucked with DB connection I configurated all good
according too me but I cant see anything added to the DB.
Was This Post Helpful? 0
  • +
  • -

#3 Denis1  Icon User is offline

  • D.I.C Head
  • member icon

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

Posted 07 September 2010 - 11:32 AM

View PostLightme, on 06 September 2010 - 05:40 PM, said:

For me this code is not seeming to work correctly it get stucked with DB connection I configurated all good
according too me but I cant see anything added to the DB.


show me your code and i will have a look at it to try and help you
Was This Post Helpful? 0
  • +
  • -

#4 Lightme  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 06-March 10

Posted 07 September 2010 - 02:32 PM

I first typed over the test connection as this:

test.php

<?php include_once("connect.php"); ?>

<html >
<head>
<title>Test</title>
</head>

<body>

<?
if (isset($_POST['Submit'])) {
$sql = "INSERT INTO users SET id = '', name = '".$_POST['name']."'";
$res = mysql_query($sql);
echo "".$_POST['name']." ADDED";
}
?>
<form id="form1" name="form1" method="post" action="">
  <p>
    <center>
      ENTER NAME <br />
      <input type="text" name="name" id="name" />
      <br />
      <input type="submit" name="Submit" id="Submit" value="Submit" />
    </center>
  </p>
</form>
</body>
</html>




connect.php


<?php
$mysql_server = "localhost"; 

$mysql_user = "root"; 

$mysql_password = "******"; 

$mysql_database = "maffiagame";

$connection = mysql_connect("$mysql_server","$mysql_user","$mysql_password") or die ("Unable to establish a DB connection");

$db = mysql_select_db("$mysql_database") or die ("Unable to establish a DB connection");
?>




I cant see nothing that it have a DB connection and also in the admin of the sql no data is added.
The DB is good configured on my local machine because my other scripts are working perfect.
Was This Post Helpful? 0
  • +
  • -

#5 Denis1  Icon User is offline

  • D.I.C Head
  • member icon

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

Posted 08 September 2010 - 05:30 AM

View PostLightme, on 07 September 2010 - 08:32 PM, said:

I first typed over the test connection as this:

test.php

<?php include_once("connect.php"); ?>

<html >
<head>
<title>Test</title>
</head>

<body>

<?
if (isset($_POST['Submit'])) {
$sql = "INSERT INTO users SET id = '', name = '".$_POST['name']."'";
$res = mysql_query($sql);
echo "".$_POST['name']." ADDED";
}
?>
<form id="form1" name="form1" method="post" action="">
  <p>
    <center>
      ENTER NAME <br />
      <input type="text" name="name" id="name" />
      <br />
      <input type="submit" name="Submit" id="Submit" value="Submit" />
    </center>
  </p>
</form>
</body>
</html>




connect.php


<?php
$mysql_server = "localhost"; 

$mysql_user = "root"; 

$mysql_password = "******"; 

$mysql_database = "maffiagame";

$connection = mysql_connect("$mysql_server","$mysql_user","$mysql_password") or die ("Unable to establish a DB connection");

$db = mysql_select_db("$mysql_database") or die ("Unable to establish a DB connection");
?>




I cant see nothing that it have a DB connection and also in the admin of the sql no data is added.
The DB is good configured on my local machine because my other scripts are working perfect.


i dont see anything wrong with your codes. i have just tried it on my server and it works fine.
Are you on a local machine? and also try creating new mysql user and try again and make sure your settings are 100% right.
Was This Post Helpful? 0
  • +
  • -

#6 scott142  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 03-September 10

Posted 08 September 2010 - 05:42 AM

$mysql_database = "maffiagame"; check to see if this is the name of the database.

This post has been edited by scott142: 08 September 2010 - 05:43 AM

Was This Post Helpful? 0
  • +
  • -

#7 Eetu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 09-September 10

Posted 09 September 2010 - 08:55 AM

Hey, heres beginner coder =)!
I need your help!
I just made CONNECT.php and TEST.php and DB is up with USER line..
but when I type my name into TEST page and press Submit:
Nothin happens!
No updates in DB no that "NAME" ADDED text!!!

Help me heres my codes:

Connect.php
<? 
$mysql_server = "localhost"; // localhost is common on most hosts.

$mysql_user = "root"; //  this is the name of your username of the server.

$mysql_password = "******"; // the password connected to the username. MAKE IT COMPLEX.

$mysql_database = "mre"; // the database name of where to connect to and where the information will be help.

$connection = mysql_connect("$mysql_server","$mysql_user","$mysql_password") or die ("Unable to establish a DB connection");

$db = mysql_select_db("$mysql_database") or die ("Unable to establish a DB connection");
?>


test.php
<?php include_once("connect.php"); ?>
<html >
<head>
<title>Test</title>
</head>

<body>


<? 
if (isset($_POST['Submit'])) {
$sql = "INSERT INTO users SET id = '', name = '".$_POST['name']."'";
$res = mysql_query($sql);

echo "".$_POST['name']." ADDED";
}
?>
<form id="form1" name="form1" method="post" action="">
  <p>
    <center>
      ENTER NAME <br />
      <input type="text" name="name" id="name" />
      <br />
      <input type="submit" name="Submit" id="Submit" value="Submit" />
    </center>
  </p>
</form>
</body>
</html>



Won't WORK! :o ! What's wrong? :S
Was This Post Helpful? 0
  • +
  • -

#8 Denis1  Icon User is offline

  • D.I.C Head
  • member icon

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

Posted 09 September 2010 - 10:12 AM

Ok this is a common error if you are using a localhost. Try using the full php tags. so instead of
<?  echo "Denis"; ?> 
you should use
<?php echo "Denis"; ?>
. Local-hosts like xampp confuse <? tage for xml and it all a big mess.
Was This Post Helpful? 2
  • +
  • -

#9 Eetu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 09-September 10

Posted 09 September 2010 - 10:16 PM

View PostDenis1, on 09 September 2010 - 09:12 AM, said:

Ok this is a common error if you are using a localhost. Try using the full php tags. so instead of
<?  echo "Denis"; ?> 
you should use
<?php echo "Denis"; ?>
. Local-hosts like xampp confuse <? tage for xml and it all a big mess.

Hey thx! <3 Its workin, I will continue this >>
And I will post if I get errors and im glad that u can help :))
Keep it up u r good coder ;)
Was This Post Helpful? 0
  • +
  • -

#10 Lightme  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 06-March 10

Posted 11 September 2010 - 08:07 PM

View PostDenis1, on 09 September 2010 - 09:12 AM, said:

Ok this is a common error if you are using a localhost. Try using the full php tags. so instead of
<?  echo "Denis"; ?> 
you should use
<?php echo "Denis"; ?>
. Local-hosts like xampp confuse <? tage for xml and it all a big mess.


That was exactly the problem. Thanks a lot.
Was This Post Helpful? 0
  • +
  • -

#11 Themitchel0  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 107
  • Joined: 14-April 10

Posted 18 October 2010 - 05:46 PM

is it possible to make a mysql database without using a server?, like can i make a local one? any help would be nice thank you!
Was This Post Helpful? 0
  • +
  • -

#12 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 925
  • View blog
  • Posts: 3,204
  • Joined: 19-January 10

Posted 24 October 2010 - 10:48 PM

View PostThemitchel0, on 18 October 2010 - 04:46 PM, said:

is it possible to make a mysql database without using a server?, like can i make a local one? any help would be nice thank you!


Why did this get -rep?


Anyhow, I believe if you wanted to, you could set up a Virtual Machine (oracle has a good one) with some server software, you can add mysql to it and host your websites database. Although, your VM and computer would have to remain turned on...
Was This Post Helpful? 0
  • +
  • -

#13 xggamer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-July 10

Posted 30 October 2010 - 09:22 AM

some help please i did all that but it then says
"Parse error: syntax error, unexpected T_IF in /home/a8037639/public_html/test.php on line 11"
this is my test code hope you can help me out thanks in advance

01 <?php include_once("connect.php"); ?>
02 <html >
03 <head>
04 <title>Test</title>
05 </head>
06
07 <body>
08
09
10 <?
11 if (isset($_POST['Submit'])) {
12 $sql = "INSERT INTO users SET id = '', name = '".$_POST['name']."'";
13 $res = mysql_query($sql);
14
15 echo "".$_POST['name']." ADDED";
16 }
17 ?>
18 <form id="form1" name="form1" method="post" action="">
19 <p>
20 <center>
21 ENTER NAME <br />
22 <input type="text" name="name" id="name" />
23 <br />
24 <input type="submit" name="Submit" id="Submit" value="Submit" />
25 </center>
26 </p>
27 </form>
28 </body>
29 </html>
Was This Post Helpful? 0
  • +
  • -

#14 xggamer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-July 10

Posted 23 November 2010 - 06:22 AM

This Doesn't matter anymore i have fixed this problem
Was This Post Helpful? 0
  • +
  • -

#15 PhpGamer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 12-March 11

Posted 12 March 2011 - 11:59 AM

Hi All i See Some Users Are Getting Unable to establish a DB connection.
I Hope This InFo Will Help Any one . Plz Note I Can Not Spell well


Just Like To Say Thanks For You tutorial on Starting

A web base php game

Named>Text Based Mafia Game Part1 Or Part2


<?php include_once("connect.php"); ?> <<< This is a key part in any script any page needs this info
So You Can establish a DB connection


Here Is The Code I Use For The connect.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>connect</title>
</head>
<?php
$mysql_server = "localhost"; // localhost is common on most hosts.

$mysql_user = "TestGameUser"; //  this is the name of your username of the server.

$mysql_password = "TestPass"; // the password connected to the username. MAKE IT COMPLEX.

$mysql_database = "testgameuser"; // the database name of where to connect to and where the information will be help.

$connection = mysql_connect("$mysql_server","$mysql_user","$mysql_password") or die ("Unable to establish a DB connection");

$db = mysql_select_db("$mysql_database") or die ("Unable to establish a DB connection");
?>
<body>

</body>
</html>
Attached Image


Here Is The Code I Use For The Test.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php include_once("connect.php"); ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Page</title>
</head>

<body><h1 align="center"><em><strong>This Is A Test Page To See If You Are Geting connect to you DB</strong></em></h1>
<hr />
<? 
if (isset($_POST['Submit'])) {
$sql = "INSERT INTO users SET id = '', name = '".$_POST['name']."'";
$res = mysql_query($sql);

echo "".$_POST['name']." ADDED";
}
?>
<form id="form1" name="form1" method="post" action="">
  <p>
    <center>
      ENTER NAME <br />
      <input type="text" name="name" id="name" />
      <br />
      <input type="submit" name="Submit" id="Submit" value="Submit" />
    </center>
  </p>
</form>


</body>
</html>

Here Is The Code I Use For The Test2.php
I Made a 2 Test page .
<?php include_once("connect.php"); ?>
<html >
<head>
<title>TestPage2</title>
</head>

<body>


<? 
if (isset($_POST['Submit'])) {
$sql = "INSERT INTO users SET id = '', name = '".$_POST['name']."'";
$res = mysql_query($sql);

echo "".$_POST['name']." ADDED";
}


// This is the bit that is new .The line below is just selecting data from users table and adding it to result
$result = mysql_query("SELECT name,id,money FROM users ORDER BY id DESC") or die(mysql_error());


// this is assingint som html for the drop down menu along with the some php and the data from result
$member_list = "";
	while($row = mysql_fetch_array( $result )) {
		if($row['name'] == $_POST['Name_list']){
		$member_list .= "<option selected=\"selected\" value=\"".$row['name']."\">".$row['name']."</option>";
		}else{
		$member_list .= "<option value=\"".$row['name']."\">".$row['name']."</option>";		
		}
	}


// the following below happend when you hit search and what it does is select data on the name you clicked on from the menu.
if(isset($_POST['Select']) or isset($_POST['update'])){

$sql = "SELECT * FROM users WHERE name='".mysql_real_escape_string($_POST['Name_list'])."'";
$query = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_object($query);
$select_money = htmlspecialchars($row->money);
}

// Updating the database with the information entered.
if(isset($_POST['update'])){
$result = mysql_query("UPDATE users SET money='".mysql_real_escape_string($_POST['money'])."' WHERE name='" .mysql_real_escape_string($_POST['Name_list']). "'") 
or die(mysql_error());	

echo "".$_POST['Name_list']."'s money have been changed.";
}
?>
<form method="post" >
  <p>
  <center>
    <p>ENTER NAME <br />
        <input type="text" name="name" id="name" />
        <br />
        <input type="submit" name="Submit" id="Submit" value="Submit" />
    </p>
    <p><br>
      <span class="cell">
      Select a Name
      <select name="Name_list" class="textbox" id="Name_list">
        <option value="<?php echo htmlspecialchars($_GET['user']);?>">Select.</option>
        <?php echo $member_list; ?>
      </select>
      </span>
      <input type="submit" name="Select" id="Select" onfocus="if(this.blur)this.blur()" value="Select">
      <br>
Change the Money
<input type="text" name="money" id="money" value="<?php echo $select_money; ?>">
    <br>
    <input type="submit" name="update" id="update" value="Update">
    <br>
    </p>
    <p>&nbsp;</p>
    <table width="50%" border="2" cellspacing="1" cellpadding="0">
      <tr align="center">
        <td colspan="3">Users Information</td>
      </tr>
      <tr align="center">
        <td>ID</td>
        <td>Name</td>
        <td>Money</td>
      </tr>
      <? 
$result = mysql_query("SELECT * FROM users") or die(mysql_error());
// keeps getting the next row until there are no more to get
	while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table?>
      <tr>
       <td><label for="<?php echo $row['id']; ?>"><?php
	$name2=$row['id'];
	echo "$name2"; ?>
    </label></td>
        <td><? echo $row['name'] ?></td>
        <td><? echo $row['money'] ?></td>
      </tr>
        <?php }// while loop ?>
    </table>
    <p>&nbsp;</p>
  </center>
  </p>
</form>
</body>
</html>

Quote

xggame

Attached Image
http://img39.imagesh...phpgamepic2.jpg
Attached Image
http://img858.images...phpgamepic3.jpg

Posted Image
Attached Image

Quote

Themitchel0

Attached Image
Ps: Plz Note That i Am A Noob & Can Not Spell Well .
I Know Some Html,php,Some Java if Any One w Like Me 2 Do a tutorial ON Part 2 send Me a MSG & i Will
If This Was Of Any Help Plz Rep Me.

Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3