Jump to content

PHP Help


driz

Recommended Posts

Okay so here is the plan:I need to build a dynamic website, where people can create an account, and then login using this account to submit scores for games they have played, the game should be chosen from a drop-down list which is fed from a database. The user can then submit their score for this game. These scores then need to displayed in order from highest to lowest.I'm fairly new to PHP, and this is a small project I am doing, but I'm not sure where to start?Could you please help me out by starting me off with some code, and explaining what each element does?Thanks. x-----------------------EDIT:Just wanted to add, that I plan on saving the account details on one text file, and the scores on another text file, and the games on another text file.

Link to comment
Share on other sites

You will be better off using a database then a bunch of text files. Go to php.net and read through the manual in the documentation section, start with the introduction and go from there.
I know basic PHP, but I have no idea where to start with a project like the one I described above.Also i wish to use text files to keep it simple. x
Link to comment
Share on other sites

Text files will not keep it simple. You would rather open a text file, read everything into an array, and loop through the array until you find what you're looking for instead of doing this:SELECT * FROM scores WHERE game_id=10There's a reason most people don't use text files to replace a database. The reasons are typically because of bad experiences the programmer had in the past working with text files. If you want to get those experiences for yourself, go ahead.The first step in a project like this is to define your data structures, however you want to store them. Either design and set up your database or make some rules about how you want the data in your files to be stored. Once you have your data storage defined then each page becomes either a page to put data into the data store, or read data from it. A logical starting point is with accounts, so first create a page to add a new account. Once you can add accounts then you can create a login page that can check the data store for the entered credentials and start a session or something like that to keep track of who is logged in. Once you have the login system working then you can work on the pages to enter scores and whatnot. There is a small login tutorial in the PHP tips topic in this forum.

Link to comment
Share on other sites

<?php// CYBER-WARS ACCOUNT FORM// Version 1.0// Author: dRiZ.co.uk?><style type="text/css" rel="stylesheet">form { margin: 0; padding: 0; }fieldset{border: #000000 2px solid;padding: 20px;width: 400px;}legend{font-size: 13px;font-family: "Verdana";}p{margin: 0 0 20px 0;font-size: 9px;font-family: "Monaco";}label { width: 100%; font-size: 9px; font-family: Monaco; }input[ type=text],input[ type=password]{width: 100%;border: #000000 1px solid;padding: 3px;font-size: 16px;font-family: "Verdana";margin: 5px 0;background: #cccccc;}input[ type=submit],input[ type=reset]{border: #000000 1px solid;padding: 3px;font-size: 13px;font-family: "Verdana";}</style><fieldset><legend>Account Credentials</legend><form name="account" action="" method=""><p>Create your CYBER-WARS ID</p><label for="username">Username</label><input type="text" name="username" /><label for="password">Password</label><input type="password" name="password" /><label for="alias">Alias</label><input type="text" name="alias" /><input type="submit" value="Create Account" /><input type="reset" value="Clear Form" /></form></fieldset>

Okay so this form will be the account creation, and will be inserted using php includeWhere do I start about connecting with a DB, and sending information to this database?Can you start me off with some PHP

Link to comment
Share on other sites

Check the MySQL reference, there are a few examples on that page and links to the other MySQL functions.http://www.php.net/manual/en/ref.mysql.phpYou will use mysql_connect and mysql_select_db to connect to the database server and select the database, and then you can send queries to it using mysql_query. If the query returns results (like a SELECT query), then you can go through the results using something like mysql_fetch_assoc to get the next row from the result. Links to all of those functions are on the MySQL reference page, and you might also want to use functions like mysql_num_rows to count the number of returned rows, or mysql_insert_id to get the last auto-generated ID. You'll also need to use mysql_real_escape_string to santize any data from the form that you will be using in the query.There are some examples in this thread:http://w3schools.invisionzone.com/index.php?showtopic=12509

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...