Home  | Login  | Register  | Help  | Play 

[Flash/PHP] Login Tutorial

 
Logged in as: Guest
  Printable Version
All Forums >> [Gaming Community] >> [Legends and Lore] >> Artists of Legend >> Art Academy >> [Flash/PHP] Login Tutorial
Forum Login
Message << Older Topic   Newer Topic >>
1/30/2010 19:56:51   
//.Shadow.\\
Member

Login Tutorial

Step 1
Requirements
MySQL Database
PHP
Flash

Step 2
Creating a Table

Open PhpMyAdmin
Login to your Database
Then press a button called "SQL".
And a box shall apear.
Now...
Make sure you change *Databasename* to your database name...
Then enter the following;
CREATE TABLE `databasename`.`users` (`id` INT(11) NOT NULL AUTO_INCREMENT, 
`username` VARCHAR(300) NOT NULL, `password` VARCHAR(300) NOT NULL, PRIMARY KEY (`id`)) ENGINE = MyISAM;


Step 3
Connecting to Database
First off all in your filemanager create a file called login.php or another name which you could remember and type the following code into the file.
<? $dbhost = 'localhost'; // Usally Localhost use this unless specifyed by host.
$dbuser = 'root'; // The username of the database you create (sometimes the same as databasename)
$dbpass = 'password'; // The database password
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');

$dbname = 'changeme'; // The database name
mysql_select_db($dbname);
?>


Step 4
Setting up the flash side of things.
First draw two text feilds username and password. Set them to a input feild and change the var name on username to 'username' and the var name on password to you guessed it 'password'.

Now create a button.
And open action script and type;
on(press){
this.user = username;
this.pass = password;
loadVariablesNum("http://www.example.com/login.php", 0, "POST");
}


Now on frame of the login we need;
_root.onEnterFrame = function(){
if(_root.loadLogin == "OK"){
_root.gotoAndStop("SUCESS");
}
if(_root.loadLogin == "KO"){
trace("Incorrect username and or password");
}
}


Step 5
Register Page
Unfortiatly to explain how to connect this with flash. After learning all this you should be able to make one your self.
So make a page called register.php or what ever.
Then first make the HTML side of things. So copy the following.
<head><title>YOUR SITE - Register</title></head>
<form action="" method="post">
Username: <input type="input" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" value="Register" name="go">
</form>

Now open the login.php and copy the PHP Database bit from last time and add it to the top (be sure to include the <? ?>).

Now we need to make the PHP bit so under the database bit put the following code.
<? 
if($_POST['go']){
$username = $_POST['username'];
$password = $_POST['password'];
$sql = mysql_query("SELECT * FROM users WHERE username='$username'");
$row = mysql_num_rows($sql);
if($row != 0){
echo"Sorry $username that Username Taken!";
}else{
mysql_query("INSERT INTO `users` (`id`, `username`, `password`)VALUES ('','$username','$password')");
echo"Regged";
}
}
?>


Step 6
Completing the login!
Now we have register and the flash and database set up the next thing to do is add the following. After the database connection.
<?
$username = $_POST['username'];
$password = $_POST['password'];
$sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'");
$row = mysql_num_rows($sql);
if($row != 0){
print"loadLogin=OK";
}else{
print"loadLogin=KO";
}
?>


If you have any complications then dont hesitate to ask here,
Parker
http://www.park-er.com

< Message edited by //.Shadow.\\ -- 9/15/2011 6:23:47 >
AQ DF MQ  Post #: 1
4/25/2013 14:53:20   
jooda
Banned


nice!
Post #: 2
Page:   [1]
All Forums >> [Gaming Community] >> [Legends and Lore] >> Artists of Legend >> Art Academy >> [Flash/PHP] Login Tutorial
Jump to:






Icon Legend
New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts




Forum Content Copyright © 2018 Artix Entertainment, LLC.

"AdventureQuest", "DragonFable", "MechQuest", "EpicDuel", "BattleOn.com", "AdventureQuest Worlds", "Artix Entertainment"
and all game character names are either trademarks or registered trademarks of Artix Entertainment, LLC. All rights are reserved.
PRIVACY POLICY


Forum Software © ASPPlayground.NET Advanced Edition