Studio Blog, Part 2

June 26, 2008 by tdavey

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.

Week 5 Studio… Process Diary

April 16, 2008 by tdavey

i feel like i have really learnt a lot, and progressed well this week.

i have created all the tables for the database, however the way i made them doesnt seem to implement them on the server where the php works, so ill need to re create them again. however its not all lost time as i learnt a lot about creating and using MYSQL, so thats good.

i have started working on a login script for the site, using some tutorials i have found. there is still a bit of work to be done here but once completed it will be a good feature of the site. it will not only let the user login and load their settings, it will remember the user, track their login using a session and things like that.

while i feel the progress being made is good, i still think there is a lot to be done and the pace will need to be picked up yet again

Week 5 Studio… Thoughts

April 16, 2008 by tdavey

yet again we are still going along nicely. although i have had my own problems to deal with lately, my own medical situations have seen me slow down a bit in everything, not just uni work and it has been hard, but i think i am still making progress slowly but surely.

i think overall i am happy with the progress, i was a little worried about how we would all go, if we would really put in the time that was needed, but i am happy and even impressed with ryans work efforts, he has done well so far and his work on the project plan took a bit of a load off my shoulders at a point in time which hasnt been easy for me too. as for my own efforts this week i have done a lot of PHP work. i have learnt a lot this week and i feel like that has been good for me, it keeps me motivated to keep on learning and i also feel like ive really learnt some skills on my own that i can use when i leave uni.

Week 4 Studio… Process Diary

April 16, 2008 by tdavey

ok, so far this week i have picked up the pace a bit and really managed to get something happening.

i have managed to install apache, mysql and php on my own laptop, which means i can basically use that as a server to remotely run parts or all of the website directly on the laptop. this is great because no matter where i am i can work on the PHP. i dont have to upload anything or even have internet access, i could work on this in the car or on the train if i wanted to. and that could be a good thing when its really coming to the deadline later on..

early tests of simple PHP scripts have shown i have learnt PHP well so far and that i have gotten it to work on this laptop nicely. the bigger test will be getting integration of PHP and MYSQL happening.

i have built all the database tables so far according to what i planned them, so they are all ready for some PHP connection from the website, im basically learning this as i go so it could be interesting, but im still enjoying the challenge.

as a group i think we are still progressing nicely and everything is going well.

Week 4 Studio… Thoughts

April 16, 2008 by tdavey

ok so this week has been much much better. i have been able to help out with the project plan more, although ryan took care of it mostly, and i have managed to get some solid work in PHP and MYSQL done.

i feel better about the project again and im sure it will be fine. i can see a really nice finished product coming out of this, and im happy with that.

so far im really enjoying learning PHP. its a challenge, learning a new language but i am grasping it well and i look forward to really using it well for this project.

as a 2 person group i think we will be fine now. in the beginning we were only going to work as the two of us and im pretty sure we can still get this done

ive realised now that its a big project, theres a lot to be done and studio will take up a lot of time this semester, i just keep telling myself its not that long and it will be worth the effort i can put in.

Week 3 Studio… Process Diary

April 16, 2008 by tdavey

so far this week has been an off week. i dont want to have many of these. with Brad leaving the group, we have been thrown off a bit. but we have concentrated on getting the project plan started mostly, although we have been given some extra time i dont want to waste too much time as it will push everything else back, and we really dont need that at all.

some other work in other subjects and some other things outside of uni have made it really hard for me to get too much done. i have refined the database design and i think we are really on track there. ive helped out ryan with the project plan too.

i will admit that not that much was done this week, i will need to pick it up for next week.

Week 3 Studio… Thoughts

April 16, 2008 by tdavey

alright! we have had another good week, and i still feel like this website is really going to plan. we have looked into the goals of the website this week, and really sorted out what the project plan will entail. Brad will take care of the project plan so that i can really start to get my head into PHP and so that Ryan can really work on the designs and starting to maybe even CSS.

at the end of the day i think Brad should be right with it all.

(added later)

as it turns out, Brad wasnt alright with it all and has decided to quit uni. It really worries me, but i have tried to remember that there must be something pretty important going on for him to leave uni like that.

still, its a big problem for us because we now have more to do in a 2 person group. I think we will be ok if we scale the project down slightly and just put our heads down, but the thing that worries me is that Brad was going to take care of all the project planing, and now we have to get that done, and take care of the other parts as well.

im sure we will be ok though, not much we can do about it and it wont do anyone any good to sit and whinge about it

Week 2 Studio… Process Diary

April 16, 2008 by tdavey

this week in class as a group we made some good progess on the actual project. we have a good clear view on what the project will do.

so i have started to plan out database designs and things of the such. i know ryan has been designing which is great.

i have been looking into 3d in flash as well, seeing how hard it will really be. if it is too much work then we may have to stick with a 2d character instead, i dont think it will be a big loss if it is.

by next week i will have all the tables done. i want to be pretty sure on what the database design will be. of course as the project grows we may find that the databases need to be changed slightly down the track to suit, but this wont be too hard at all.

ive had a look into MYSQL but i think i need to research further into how it will work.

we also looked at buying a domain name for this site so we can host it on its own .com website.

Week 2 Studio… Thoughts

April 16, 2008 by tdavey

this week has been really productive so far. as a group we managed to get a really good idea down on paper of what the project will do, and how we will have to go about doing it.

some other ideas were thrown around, about other possible projects but they really dont have any strength to them so we decided to run with this original idea.

at this stage we seem to be progressing nicely, i like the fact that we have organised a lot of stuff already as a group and we will be able to just throw it all together in the project plan.

personally i seem to have taken a bit of control, almost the project leader. the other two seemed like they needed to assigned certain roles, which is understandable, because with so much to do, we really needed to give everyone set tasks. i decided myself that Ryan would be best for designing to visual aspects of the site. as i am a good friend of Ryans, i already know and have seen his good work in CSS and HTML, i know he can design a nice looking site and would be best out of the three of us. While Ryan does already have PHP and MYSQL experiance, i think i will take care of as much of this as i can. i really want to expand my own skills here and i think its best for me to take care of it. i know i can pick it up quickly and i will really enjoy the challenge.

as for Brad, i was a bit unsure with what he could really do. he was assigned the designs of the tshirts, he has had some photoshop, illustrator experiance so he can take care of that, as well as the project plan and some other business side type things for now. he kind of needs to fill in the spaces, but i want to make sure he has plenty of input on this project, for the groups sake and also for his own good so he can learn something from this subject.

Week 1 Studio… Process Diary

April 16, 2008 by tdavey

Week 1 has been more of a big brainstorm for us. we knew the sort of thing we were looking at, but not exactly what we were going to do. so we started to think about the kinds of web business sites we could create.

my idea was to have something dynamic and fun, something a bit different to what most people have seen before.

we went through a brainstorming process to think about some possible ideas

brainstormingideas

the one that stood out the most for all of us was a Tshirt/clothing site, where a user could try on clothes on the site, and have a character that could be customised to suit their own personal appearance and look. the concept is, that you can ‘try’ on your clothes, even when you shop online.

i think this is the idea that we will run with, its the best idea in my opinion and will be best for expanding, and making it something really cool. some feed back from other friends/family found that they would enjoy using a site like that.

obviously not too much has gone on this week, we will take the next week to see if any other totally awsome ideas come up.