The Login System
This section has the hardest part of the system to complete and develop.
a PHP based system, with interaction to MYSQL databases located on the server, the login system is designed to give each user a unique identity. by using cookies and sessions, each user would be remembered and identified as they move around the site, so each user can save their settings and preferences as they go.
i expected this to be hard, and it was.
I started out with looking through the world wide web to try and find a nice tutorial. Turns out as a PHP programmer with basically no previous experience, i might have gotten myself in over my head there.. hmm. it seems simple enough, a simple database to store the users username, password and any other data needed for the site. when the user enters their username and password into the form given on the homepage, the from passes the variables to PHP, which uses them in an SQL query to check the database values for a match of one, and one only. Sounds simple enough? well, not really i guess. but i thought so at the time.
Its something that took a long time to complete in the end, although the way up to the end in fact.
the first part of the section i did complete was the page where users can create an account on the site. this involved adding new data to a database.
the code for adding to the database..
<?php
$username = $_REQUEST['username'] ;
$password = (sha1(strip_tags($_REQUEST['password']))) ;
$firstname = $_REQUEST['firstname'] ;
$surname = $_REQUEST['surname'] ;
$dob_day = $_REQUEST['dob_day'] ;
$dob_year = $_REQUEST['dob_year'] ;
$street = $_REQUEST['street'] ;
$suburb = $_REQUEST['suburb'] ;
$postcode = $_REQUEST['postcode'] ;
$state = $_REQUEST['state'] ;
this section receives the variables from the HTML form. each one is assigned to a PHP variable so it can be inserted into an SQL command to be inserted into the database table
/**
* Connect to the mysql database.
*/
$conn = mysql_connect(“localhost”, “root”, “”) or die(mysql_error());
mysql_select_db(‘ipclothing’, $conn) or die(mysql_error());
the section above connects to the database
$sql=”INSERT INTO users (username, password, first_name, surname, dob_day, dob_month, dob_year, street_address, suburb, postcode, state)
VALUES
(‘$_POST[username]‘,’$_POST[password]‘,’$_POST[firstname]‘,’$_POST[surname]‘,’$_POST[dob_day]‘,’$_POST[dob_month]‘,’$_POST[dob_year]‘,’$_POST[street]‘,’$_POST[suburb]‘,’$_POST[postcode]‘,’$_POST[state]‘)”;
the sql command above inserts the data from the PHP variables into the database
if (!mysql_query($sql,$conn))
{
die(‘Error: ‘ . mysql_error());
}
echo “Account Created Successfully”;
a simple check to make sure everything works, if it doesnt, it stops the script.
?>
for the most of the script, it has been adapted from an online tutorial, found here
http://hvassing.com/2007/simple-php-login-script-using-session-and-mysql/
along the way, a lot of the code didnt work first try. there were two main reasons, the first of which being syntax and coding errors. an example of this is mixing up placing of code in IF statements which reversed the process, meaning if your login was incorrect, it would let you login. funny once it had been figured out!
the other reason was that the database design, code or website wasnt designed exactly the way it needed to be. this was because as the project went on, we realised certain things wouldnt work the way we planned and had to be modified slightly to accommodate for everything we needed the script to do. once we realised what needed to be changed, most of these problems were overcome with some careful thinking and planning.
<?php
// Start a session
session_start();
// Sends the user to the login-page if not logged in
if(!session_is_registered(‘member_ID’)) :
header(‘Location: index.php?msg=requires_login’);
endif;
// Include database information and connectivity
include ‘db.php’;
// We store all our functions in one file
include ‘functions.php’;
?>
this code is placed at the top of each page where a user must be logged in, it checks that their session is registered and matches the user details in the database
<?php print user_info(‘username’); ?>
this small snippet of code prints the users name back.
Profile Creator
one of the main sections of the site, i took the part of putting this together. a lot of work went into the making of the profile creator and a few headaches too. first of all i tried to put this together in HTML, which was no good. i used a group of HTML form based group boxes, with the characters options in each. this worked fine for sending the data to the database to be saved, however it was a lot more difficult when it came to getting the character to show its selected profiles on the screen. it could be done but i wanted to try and have the site use more dynamic technologies, so i decided to build the section in flash.
it was designed to be simple and easy to use. combo boxes are placed on the side to give choices on the features, and the character in the middle updates as you select an option.
when it came to saving the profile, there was a fair bit involved. A fair bit of code went into the flash application, and the PHP and MYSQL in the background. A lot of time and trial and error went into it as well, making it very time consuming, meaning the progress on the login pretty much came to a standstill. With advice from Matt, i went through the steps the proccess would take itself, keeping each bit as simple as possible to test each part of the code worked, first using a text book example i used SENDANDLOAD from actionscript to take variables with combobox variables loaded into them. the variables are POSTED to PHP, where they recieve them, and process them into PHP variables. it gets more complicated as the PHP variables are then sent into the sql which is then inserted into the database. once this entire process is complete the flash needs to be sent back a text string to say everything worked, so it could be displayed on the screen. otherwise, no one would ever know if it actually worked or not.
<?php
$gender = $_POST['gender'];
$profileName = $_POST['profileName'];
$skinStyle = $_POST['skinStyle'];
$body = $_POST['body'];
$hair = $_POST['hair'];
$eyes = $_POST['eyes'];
$mouth = $_POST['mouth'];
$success_string = “Profile Saved Successfully”;
// open connection to database
$conn = mysql_connect(“localhost”, “root”, “”) or die(mysql_error());
mysql_select_db(‘ipclothing’, $conn) or die(mysql_error());
$sql=”INSERT INTO profile (profile_name, gender, skin, body, hair, eye, mouth)
VALUES (‘$profileName’,'$gender’,'$skinStyle’,'$body’,'$hair’,'$eyes’,'$mouth’)”;
if (!mysql_query($sql,$conn))
{
die;
}
print “&scriptStatus=” . $success_string;
?>



in the code above (PHP) the variables are recieved and then sent to the MYSQL, then a string is sent back.
Planning
along the way, a lot of planning and thinking was done to make sure i was clear on what i was actually doing. Tables which show combo box layouts, so i knew which selections would return which values.
i find that by conceptualising and visualising things on paper, before putting them into code gives me a real idea in my head of what is actually going on. for example:
COMBO BOX TABLE
this table shows combo boxes, what goes in them, what values are assigned and which images in flash should be shown to view the respective selection.
GENDER…..Value……Image
Male…………….0
Female…………1
SKIN
White……………0
Light Brown……1
Dark Brown…….2
Dark
BODY
Small 0
Medium 1
Large 2
HAIR
Short 0 hair_0.png
Medium 1 hair_1.png
Long 2 hair_2.png
Messy 3 hair_3.png
EYE
Small 0
Medium 1
Large 2
MOUTH
Blank 0
Smile 1
Big Smile 2
Cool 3
As you can see the table shows how the combo box system works.
Final Thoughts
in the end the project was incomplete, i wasnt happy with it, in fact i was disappointed. we should have achieved more and i think other group members could have tried harder than they did throughout the course of the project. I do think i have learnt a lot about PHP and MYSQL as well as ACTIONSCRIPT, which is fantastic, its also helped me a lot to plan out and take on such a big project, project management and team leadership skills as well, and even if the final mark doesnt show as much, i think there is a lot to take from the semester’s work. it also makes me consider my next semester of Studio and how i will attack it. i feel now like working in a group can really have its downfalls and i dont like the idea of having to rely on other people to pull you through, you are relying on them for good marks too. a lot rides on it, and i dont like that idea. In the real world, you have your part and at the end of the day, your wage is paid to you regardless of whether the rest of the team pulls their weight or not.
having said that, my time management skills can be improved and although outside and inside of uni work, this has been a very difficult few months for me personally, i think deep down i am somewhat happy with what i have achieved. After the problems i have faced, i am stronger and smarter, more ready to tackle semester two with full force.
