Jump to content

Archived

This topic is now archived and is closed to further replies.

adamscybot

Creating a small clan script

Recommended Posts

If someone could give me examples for the following I would appreciate it so much. ima newbie in PHP and you uber people will find this easy.

Basically, I have 2 pages which I want a small admin panel for so i can quickly and easily edit them. These 2 pages are here:

1. [a href=\"http://sws.vxcomputers.com/civilclan/roster.php\" target=\"_blank\"]http://sws.vxcomputers.com/civilclan/roster.php[/a]
2. [a href=\"http://sws.vxcomputers.com/civilclan/matches.php\" target=\"_blank\"]http://sws.vxcomputers.com/civilclan/matches.php[/a]

At the moment, I need an admin panel for (1) more than (2).

So what i want is to be be able to log in, type a memebers name in the text box and then select his rank in a text box. I then click add and its added to the roster page under the correct heading.

E.g. I put a member named 'steven' in the box and select 'on trial.' I then check the rosters page and steven's name is under on trial.

The script should allow me to list the members and let me edit there status (e.g. from 'on trial' to 'member'). It should also allow me to delete a member and edit the players name.

Also, on the main page (http://sws.vxcomputers.com/civilclan/) I have a small box on the left telling of new members. The admin panel should automatically add the player to this (preferably only if there rank is 'member' or higher) and then remove it after 30 days or so. This part only needs to show their name.

I realise im asking for a lot to be done. I would be so, very, very, very grateful. I cant express who much it would help. hey, if you play CSS or HL2: DM you can join the clan!

Many thanks,
Adam

Share this post


Link to post
Share on other sites
I'm kinda n00b to the whole php/mysql thing but I shouldnt think it would be to hard
You could make a MySQL database to to cover information for both the roster and matches,
Ive included some code example below for creating the roster and members page.
Goodluck with making this, feel free to send me some finished code lol

Note that these pages are NOT secure and that you will need to incorporate some sort of login to secure them.

Create Database named 'clanwar' through MySQL then run following SQL Query

[code]CREATE TABLE `matches` (
  `opponent` varchar(30) NOT NULL default '',
  `date` datetime NOT NULL default '0000-00-00 00:00:00',
  `maps` varchar(50) NOT NULL default '',
  `score` varchar(10) NOT NULL default ''
) TYPE=MyISAM;
[/code]

[code]CREATE TABLE `members` (
  `id` int(4) NOT NULL auto_increment,
  `user` varchar(25) NOT NULL default '',
  `firstname` varchar(15) NOT NULL default '',
  `lastname` varchar(15) NOT NULL default '',
  `position` varchar(15) NOT NULL default '',
  `email` varchar(30) NOT NULL default '',
  `rank` varchar(15) NOT NULL default '',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM AUTO_INCREMENT=5;
[/code]

next a file to hold our MySQL details in, create private.inc.php with following code:

[code]<?

$username="root";            //MySQL  username
$password="pass";            //MySQL  passwrd
$database="clanwar";        //MySQL database name

?>[/code]

next a script to insert the details into the database, create insert.php with following code
note that I havent included a redirect at the bottom because well I couldnt remember the code for that lol

[code]<html>
<head>
  <title>Roster - Insert Details</title>
  <meta http-equiv="Content-Type" content="text/html; charset=unicode">
  <meta name="keywords" content="test page">
  <link rel=StyleSheet href="style.css" type="text/css">
</head>

<?

/*
This script written by raVest.
Created on the 26/04/2006
Website: http://ravestyles.com

Member management system with backend for the
creation, updating and deletion of users from a MySQL
database. Please contact raVest if you have any concerns
or isses on trance@ravestyles.com
*/

include("private.inc.php");

$user=$_POST['user'];
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$position=$_POST['position'];
$email=$_POST['email'];
$rank=$_POST['rank'];

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO members VALUES ('','$user','$firstname','$lastname','$position','$email','$rank')";
mysql_query($query);

mysql_close();

?>[/code]

And also a page to input these details from, signup.html

[code]<html>
<head>
  <title>Signup Page</title>
  <meta http-equiv="Content-Type" content="text/html; charset=unicode">
  <meta name="keywords" content="test page">
  <link rel=StyleSheet href="style.css" type="text/css">
</head>
<font class="itext">
<form action="insert.php" method="post">
Username:  <input type="text" name="user"><br>
First Name: <input type="text" name="firstname"><br>
Last Name: <input type="text" name="lastname"><br>
Clan Position: <input type="text" name="position"><br>
E-mail: <input type="text" name="email"><br>
<label for="rank">Rank:</label>
<select name="rank" id="rank">
<option selected value="Choose One">Choose One...
<option value="Administrator">Administrators
<option value="Channel Admin">Channel Admin
<option value="Members">Members
<option value="Trial">On Trial
</select><br>
<input type="Submit">
</form>
</font>[/code]

then we can output all the info onto a roster, this is a basic page which just lists the info from the database, I havent built up a table to display it how u would like but you can play around with this. Create roster.php with following code:

[code]<html>
<head>
  <title>Roster (Members and Admins)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=unicode">
  <meta name="keywords" content="test page">
  <link rel=StyleSheet href="style.css" type="text/css">
</head>

<?

/*
This script written by raVest.
Created on the 26/04/2006
Website: http://ravestyles.com

Member management system with backend for the
creation, updating and deletion of users from a MySQL
database. Please contact raVest if you have any concerns
or isses on trance@ravestyles.com
*/

include("private.inc.php");

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM members";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo "<font class=ihead><center>Roster [<a href=signup.php>Add member</a>]</center></font><br><br>";

$i=0;
while ($i < $num) {

$user=mysql_result($result,$i,"user");
$firstname=mysql_result($result,$i,"firstname");
$lastname=mysql_result($result,$i,"lastname");
$position=mysql_result($result,$i,"position");
$email=mysql_result($result,$i,"email");
$rank=mysql_result($result,$i,"rank");

echo "<font class=itext>Player Name:$user<br>Real Name: $firstname $lastname<br>Position: $position<br>Email: $email<br>Rank: $rank<br></font><hr><br>";

$i++;
}

?>[/code]

Heres a stylesheet to use with it as well for testing purposes, name it style.css
[code]/*
website    www.ravestyles.com
creator       Jarrod W (www.ravestyles.com)
updated    26/04/2006
created for use with the member management system
*/

.bodyline {background:#E5E8EE;border:1px ridge #000000}
body {background: #246193; color:#FF9900; font: Arial; font-weight: bold; font-size: 12px; }

A:link      {COLOR: #FFFFFF; FONT-SIZE: 12px; FONT-FAMILY: Verdana, Helvetica; TEXT-DECORATION: none}
A:active    {COLOR: #FFFFFF; FONT-SIZE: 12px; FONT-FAMILY: Verdana, Helvetica; TEXT-DECORATION: none}
A:visited   {COLOR: #FFFFFF; FONT-SIZE: 12px; FONT-FAMILY: Verdana, Helvetica; TEXT-DECORATION: none}
A:hover     {COLOR: #C0C0C0; FONT-SIZE: 12px; FONT-FAMILY: Verdana, Helvetica; TEXT-DECORATION: none}

.ihead {

    font-family: Verdana, Helvetica, Arial, sans-serif;
    font-size: 24px;
    font-weight: bold;
    color: #FEEFB4;
}

.itext {

    font-family: Verdana, Helvetica, Arial, sans-serif;
    font-size: 10px;
    font-weight: bold;
    color: #FF9900;
}

.iheaders {

    font-family: Verdana, Helvetica, Arial, sans-serif;
    font-size: 12px;
    font-weight: bold;
    color: #FFFFFF;
}[/code]

Below is what I have come up with so far for editing/deleting information from the roster but haven't completed yet and not sure if it works, feel free to build on the code if you wish though. Again none of these pages have a redirect on them, sorry about that.

This page should be used to collect info for updating or user to be deleted, this should be linked to the $id's pulled from the MySQL database to work with variables, i.e update.php?id=1
here is the code I have so far:

[code]<html>
<head>
  <title>Ravestyles NZ Dev - Test Page</title>
  <meta http-equiv="Content-Type" content="text/html; charset=unicode">
  <meta name="keywords" content="test page">
  <link rel=StyleSheet href="style.css" type="text/css">
</head>

<?

/*
This script written by raVest.
Created on the 26/04/2006
Website: http://ravestyles.com

Member management system with backend for the
creation, updating and deletion of users from a MySQL
database. Please contact raVest if you have any concerns
or isses on trance@ravestyles.com
*/

$id=$_GET['id'];
include("private.inc.php");
mysql_connect(localhost,$username,$password);

$query=" SELECT * FROM members WHERE id='$id'";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();

$i=0;
while ($i < $num) {
$user=mysql_result($result,$i,"user");
$firstname=mysql_result($result,$i,"firstname");
$lastname=mysql_result($result,$i,"lastname");
$position=mysql_result($result,$i,"position");
$email=mysql_result($result,$i,"email");
$rank=mysql_result($result,$i,"rank");

++$i;
}

?>

<font class="itext">
<form action="updated.php" method="post">
<input type="hidden" name="ud_id" value="<? echo $id; ?>">
Username: <input type="text" name="ud_user" value="<? echo $user; ?>"><br>
First Name: <input type="text" name="ud_first" value="<? echo $first; ?>"><br>
Last Name: <input type="text" name="ud_last" value="<? echo $last; ?>"><br>
E-mail Address: <input type="text" name="ud_email" value="<? echo $email; ?>"><br>
Rank: <input type="text" name="ud_rank" value="<? echo $rank; ?>"><br>
<input type="Submit" value="Update">
</form>
<form action="deleted.php" method="post">
<input type="hidden" name="ud_id" value="<? echo $id; ?>">
<input type="Submit" value="Delete">
</form>
</font>[/code]

This is the script that will actually update the information, updated.php:

[code]<html>
<head>
  <title>User Updated</title>
  <meta http-equiv="Content-Type" content="text/html; charset=unicode">
  <meta name="keywords" content="test page">
  <link rel=StyleSheet href="style.css" type="text/css">
</head>
<?

$ud_id=$_POST['ud_id'];
$ud_user=$_POST['ud_user'];
$ud_first=$_POST['ud_first'];
$ud_last=$_POST['ud_last'];
$ud_email=$_POST['ud_email'];
$ud_rank=$_POST['ud_rank'];

include("private.inc.php");
mysql_connect(localhost,$username,$password);


$query="UPDATE members SET user='$ud_user', first='$ud_first', last='$ud_last', email='$ud_email', rank='$ud_rank' WHERE id='$ud_id'";
mysql_query($query);
echo "Roster Updated";
mysql_close();

?>[/code]

This is the script which will actually delete the user, note the only diff between this and the update.php file is the $query sent to the MySQL. this is to be named deleted.php:

[code]<html>
<head>
  <title>Ravestyles NZ Dev - Test Page</title>
  <meta http-equiv="Content-Type" content="text/html; charset=unicode">
  <meta name="keywords" content="test page">
  <link rel=StyleSheet href="style.css" type="text/css">
</head>
<?

$ud_id=$_POST['ud_id'];
$ud_user=$_POST['ud_user'];
$ud_first=$_POST['ud_first'];
$ud_last=$_POST['ud_last'];
$ud_email=$_POST['ud_email'];
$ud_rank=$_POST['ud_rank'];

include("private.inc.php");
mysql_connect(localhost,$username,$password);


$query="DELETE members SET user='$ud_user', first='$ud_first', last='$ud_last', email='$ud_email', rank='$ud_rank' WHERE id='$ud_id'";
mysql_query($query);
echo "Roster Updated";
mysql_close();

?>[/code]

Share this post


Link to post
Share on other sites
If and when you've done your setup for MySQL. You can then query the creation date to see what accounts have been created in the last 30 days and display them to the visitors as new users

Share this post


Link to post
Share on other sites
Thank you ever so much. i can't thank you enough.

I will compile this now and add anything I think I might need toedit.

I will then give you the compiled code if you wish ;)

Adam

Share this post


Link to post
Share on other sites
Hmmmm, not sure if it is working at all?

I have not linksed any of the pages or anything because it doesnt seemt o be adding stuff into the database at all.

The database is created and all and when I try to insert something it just goes to the blank page as expected. I then check the database and theres nothing.

When I look at roster.php this is what I get:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Roster [Add member]


"; $i=0; while ($i < $num) { $user=mysql_result($result,$i,"user"); $firstname=mysql_result($result,$i,"firstname"); $lastname=mysql_result($result,$i,"lastname"); $position=mysql_result($result,$i,"position"); $email=mysql_result($result,$i,"email"); $rank=mysql_result($result,$i,"rank"); echo "Player Name:$user
Real Name: $firstname $lastname
Position: $position
Email: $email
Rank: $rank

"; $i++; } ?>[/quote]

Is this ment to happen?

Im not sure how to link collect.php (thats what i called it) to update.php and delete.php either.

Here is the compiled files in a .rar which are completely unchanged (except for the roster.php - the 'add member' link pointed to signup.php and not signup.html).

LINK REMOVED - SEE BELOW POST

I know a lot of clans want something like this, something where you can simply use php include to make it suitable for any page and not to be forced to use php nuke and all.

This could certainly be the only script around to do this!

EDIT: Hmmmm, roster .php just seems to display the 2 end characters (" and ;) on line 33 and everything after line 33. There doesnt seem to be an error?

Deleteting line 33 gives me this on roster.php:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
Player Name:$user
Real Name: $firstname $lastname
Position: $position
Email: $email
Rank: $rank

"; $i++; } ?>[/quote]

Still not right. Its displaying the code!

May I also ask what the 'Clan position' is for on signup.html! Im not sure what to put it in there as youve already got 'rank'. Is it safe to remove?

Adam

Share this post


Link to post
Share on other sites
You've changed a small bit of code which is why it's not inserting properly and it isn't reading properly
Give this a try [a href=\"http://ravestyles.com/downloads/phpClanScript-v0.2.rar\" target=\"_blank\"]http://ravestyles.com/downloads/phpClanScript-v0.2.rar[/a] and let me know how it goes :)

Im quite busy in getting a new BitTorrent site going so don't have to much time to be debugging code but Id be really keen to get some custom code for a clan site Id like to get up for our CS Clan :)

Goodluck with it, P.S the files you have shared, you might want to remove the details from the private.inc.php, the reason I made it seperate is to keep it safe and not to share details lol

Share this post


Link to post
Share on other sites
Thanks very, very much. The text is now inputted corectly into the database and is viewed correct to.

However, Im not sure how to work the update/delete function. When I visit collect.php - a form is shown. What do I put here? I tried putting anytihng and it says 'roster updated'. However, nothing changes in the database so how do I update/delete people. Is it possible to make it so on collect.php it shows all the members in the database and next to each one is an update/delete button.

More importantly, do you know of a way to output roster.php in categories. So down the page you have the headings and then roster.php automatically puts the emmebrs under them in terms of rank? Like the one shown in the link on the first post.

Thanks. You have been so much of a help.

Adam

Share this post


Link to post
Share on other sites
lol alright its 3.20am here and I'm off to bed. Here is another update for you however the update still isnt going through properly as the boxes should be filled in with the existing information, so u can just go over the top of them. This however inserts the id's as needed, so you may need someone bit more experienced to have a look at the script. And also why it is getting a numrows error

[a href=\"http://ravestyles.com/downloads/phpClanScript-v0.3.rar\" target=\"_blank\"]http://ravestyles.com/downloads/phpClanScript-v0.3.rar[/a]

Remember this is all from scratch, You may also see an install folder I've added in. don't use that as It is for database setup but I haven't finished that script.

Goodluck :)

Share this post


Link to post
Share on other sites
Thanks again. Im integrating some checks to stop users direct linking to insert.php causing a blank entry.

Adding more too,
Adam

Share this post


Link to post
Share on other sites
Im having some trouble. To stop the user going on insert.php I did the following:

Add:

[code]if (isset($_POST['Submit'])) {[/code]

Before:

[code]$user=$_POST['user'];[/code]

Add:

[code]} else {
        header("Location: $error1");
}[/code]

After:

[code]mysql_close();[/code]

What this should do is check that information has been submitted and if so, insert it. If not, redirect the user to $error1 (which ive stored in provate.inc.php).

It does work, but it works too much!! Everytime I submit info on signup.php it leads me to error1. I cant find a way to make this work...

I have also added redirects on insert.php so when information is submitted you go back to the roster. The redirect code is:

[code]header("Location: YOURPAGE");[/code]

Hopefully, I can get the insert.php check working and add more checks to make sure at least the username and rank is filled in before submitting. I probably use javascript for that.

In the mean time, I hope you can get the update/delete options working!

Thanks,
Adam

Share this post


Link to post
Share on other sites
Brilliant! I have the insert.php check working. I will now complete the form checks and give you it as V0.5 soon. Here is what I did for the insert.php check if you want to know:

First I added the error1 variable in private.inc.php. You might see some more added variables in there on V0.5.

In signup.php add:

[code]<input type="hidden" name="_submit_check" value="1"/> [/code]

After:

[code]<input type="Submit">[/code]

In insert.php add:

[code]if (array_key_exists('_submit_check', $_POST)) {[/code]

Before:

[code]$user=$_POST['user'];[/code]

Add:

[code]} else {
        header("Location: $error1");
}[/code]

After:

[code]mysql_close();[/code]

In my case, you add that after "header("Location: $rosterpage");" which is a redirect ive added to a variable of the roster.php stored in private.inc.php.

I will soon finish V0.5!

I am also on planning creating an index.php with login and links to all the pages.

Adam
PS Does your CSS clan have a server or a teamspeak?

Share this post


Link to post
Share on other sites
Just to keep you updated - here is what Ive added so far for v0.5. I hope after this release, we can see about getting the delete/editing working.

Added:

* Check that at least the username has been entered - javascript used.
* Error page displayed when insert.php, updated.php or deleted.php is opened without submitting on signup.php or collect.php first. URL of error page defined in private.inc.php.
* URL of roster page defined in private.inc.php.
* New layout for collect.php and signup.php.
* A few other tweaks

Soon to come:

* Main page - index.php
* Split results on roster.php - amount of results defined in private.inc.php.
* Backup/mass delete options
* Login using sessions

We still need some things doing though. Like:

* An output page. A different roster.php without the add member and edit buttons that can be easily arranged in terms of rank. You then use php include to put it on your website.
* Edit/delete functions - working
* Some other bits and bobs

Adam

Share this post


Link to post
Share on other sites
Hey sorry been really busy with work and coding my new website.
You managed to get the update/delete script working?

Share this post


Link to post
Share on other sites

×

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.