Monday, December 22, 2008

First Tutorial - Users Setup

User Creation
-----------------
Description :
In this tutorial, we will make a register form and a database to input the data of our users.
----------------------------------------

Alright, for my first tutorial, we will make a simple form where you can allow your "visitor" to sign up for your website.

I have WAMP(Windows Apache MySQL PHP).
So I am working on my localhost(on my local internet server/computer).
If you don't have WAMP or LAMP or an internet host, get one now.
I'll make a tutorial later on setting up WAMP..etc, but in the meanwhile there are many out on the world wide web.


Ok, I am working with PHPMyAdmin, but for those who work with the command line MySQL, i will (later) provide the codes for them, although it is pretty straight forward and almost the same as php commands for mysql.

Alright, Let's begin :D

Step 1 : Create the database.
First you need a database to store the information. You can't store eggs when there's no fridge :P

So , make a database called tutorial (or whatever you want) and make a table called users, with 3 fields.

Fill the page like this :
ID - int - 255 - latin1_bin - - not null - -auto_increment - PRIMARYKEY

Field Type Length/Values1 Collation Attributes Null Default2 Extra

That's the order ^^
For the next 2 fields,
just fill in username and pasword as the FIELD , varchar as the type, 255 as the length, and LEAVE THE REST ALONE.

After that, Save the table and let's get ready to work with php.

------------------------------

Step 2 : Php File

.
Make a file called "user_reg.php" (save it as 'All Files' in notepad).


Now see the code below. It's commented, but i will explain it as well ^_^






Registration Form

//My connections are in a different file. It's much easier to work.
require('conn.php');
?>
//Now we will work with html, to create the form
//The HASH# means that it will direct us to this page only.

Username :

Password :




if ($_POST["submit"]) {
//checking to see if there is already an existing username
$select=mysql_query("SELECT * FROM users WHERE username='$_POST[username]'");
//counting the number of records with the same username
$cselect=mysql_num_rows($select);
if ($cselect >0) {
//If the count is more than zero, then stop.
$text="Sorry, but there is already an existing user. Try again!";
}
else {
//if the count is 0 , then register the user
$insert=mysql_query("INSERT into users (username,password) VALUES('$_POST[username]','$_POST[password]')");
$text="You have been registered!";
}
}
echo $text;
?>


Sunday, December 21, 2008

Php Utopia

Hello and welcome to Php Utopia >:)
Over here, you can and soon will find many tutorials dedicated to , mainly , PHP (mostly php gaming).
You might also find, from time to time, Graphic Tutorials on various things.

So anyways, wait for my first tutorial ^_^

~Adarsh