FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


php login (with flash)





m-productions
[I have found out what the problem is, please read the bottom for the problem]


ok this is very weird, im learning how to make me a nice flash login where you can make an account then login. Now heres whats weird, the first part (making the account) works great, I even can go to the mysql database and see that it has worked. However when I go to the login.swf, for some reason this dosnt work, so heres my scripts

Register.swf
Code:
var lvSend:LoadVars = new LoadVars();
var lvReceive:LoadVars = new LoadVars();

tMessage.autoSize = true;
mcAge.tInput.restrict = "0-9"column in mySQL will cause an error

mcRegister.onRelease = function() {
   var valid:Boolean = validateForm();
   
   if(valid){
   //gather information and put in loadvars object
   lvSend.username = mcName.tInput.text;
   lvSend.password = mcSurname.tInput.text;
   lvSend.gold = mcAge.tInput.text;
   lvSend.email = mcEmail.tInput.text;
   
   //send information php script for insertion into database
   lvSend.sendAndLoad("registration.php", lvReceive, "POST");
   }else{
      alert("Please complete all fields");   
   }
};

lvReceive.onLoad = function(success:Boolean) {
   if (success) {
      if(this.result == "emailExists"){
         alert("This email address already exists in the database. Please choose another");
      }else if (this.result == "success") {
         tMessage.text = "Thank you for registering. Your password has been sent to your email address";
         clearTextFields();
      } else {
         tMessage.text = "I'm sorry there has been an error with your registration";
      }
   }
};



function validateForm():Boolean{
   if(mcName.tInput.text == "" || mcSurname.tInput.text == "" || mcAge.tInput.text == "" || mcEmail.tInput.text == ""){
      return false;      
}
        return true;
}


function clearTextFields():Void{
   mcName.tInput.text = "";
   mcSurname.tInput.text = "";
   mcAge.tInput.text = "";
   mcEmail.tInput.text = "";
}




now the registration.php
Code:

<?php
//--------------------MYSQL DETAILS ---------------------------------------//

//mysql details
require_once("dbDetails.php");


//------------------GATHER FORM DETAILS ---------------------------------//


$username = $_POST['username'];
$gold = $_POST['gold'];
$email = $_POST['email'];
$password = $_POST['password'];




//----first check the email addres does not exist already
$SQL = "SELECT * FROM members_tbl WHERE username ='".$username."'";
$rs = mysql_query($SQL,$conn);
$numRows = mysql_num_rows($rs);
if($numRows > 0){
   echo '&result=emailExists&';
   exit();//abort php script
}


//--------insert into database------------------------------//

$insertSQL = "INSERT INTO members_tbl(username, gold, email, password) VALUES ('$username', '$gold', '$email', '$password')";

$rs = mysql_query($insertSQL,$conn);


if($rs){
  //send user email with password
   sendEmail();
   echo '&result=success&';
}else{
  echo '&result=failure&';
}


//------------------- EMAIL FUNCTIONALITY--------------------------//


function sendEmail(){
   $yourname = 'yourname'; //PUT YOUR NAME HERE
   $youremail = 'you@yourdomain.com';//PUT YOUR EMAIL ADDRESS HERE
   
   //to user
   $headers = "From: $yourname <$youremail>\n";
   $headers .= "Reply-To: $yourname <$youremail>\n";
   $headers .= "MIME-Version: 1.0\n";
   $headers .= "Content-type: text/html; charset=iso-8859-1";
   
   
   //the message body
   $message = "Dear ".$GLOBALS['firstname'].",<p> Thank you for registering your password is ".$GLOBALS['randomPassword']."</p>";
   
   
   mail($GLOBALS['email'], "Your login details", $message, $headers);
}

?>





now that part works, perfectly, i can go into my database and i see a table that has

Id | username | gold | email | password |
1 | molster | 50 | email@email.com | molster |


looks perfects... now i have the following


login.swf
Code:

var lvSend:LoadVars = new LoadVars();
var lvReceive:LoadVars = new LoadVars();

tError.autoSize = "right";

mcLogin.onRelease = function() {
   lvSend.username = user.text;
   lvSend.password = pass.text;
   lvSend.sendAndLoad("logincheck.php", lvReceive, "POST");
};

lvReceive.onLoad = function(success:Boolean) {
   if (success) {
      if (this.login == "success") {
         getURL("members.php");
      } else {
         tError.text = "I'm sorry you did not enter valid login details";
      }
   } else {
      trace("no reponse from server");
   }
};


and the logincheck.php
Code:
 
<?php
session_start();
$username = $_POST['username'];
$password = $_POST['password'];

//mysqldetails
require_once("dbDetails.php");

$SQL = "SELECT * FROM members_tbl WHERE username ='".$username."' AND password = '".$password."'";

$rs = mysql_query($SQL,$conn);
$numRows = mysql_num_rows($rs);



if($numRows > 0){
   $_SESSION['loggedIn'] = true;
   echo '&login=success';
}else{
   echo '&login=failure';
}

?>





it looks fine to me, but its not working for some reason... I just cant tell why...honstly knowing me, its a typo somewhere in that script, but i cant see it.

edit: ok ive been trying to figure this out on my own, and on the last php script i found out that somthing to do with the "username" is not correct.

if i take this part of the script
Code:
$SQL = "SELECT * FROM members_tbl WHERE username ='".$username."' AND password = '".$password."'";


and change it to
Code:
$SQL = "SELECT * FROM members_tbl WHERE password = '".$password."'";



it will now work..... =(
hexkid
m-productions wrote:
... its not working for some reason...
If you don't know the reason it doesn't work ask PHP to tell it to you
Code:
$rs = mysql_query($SQL,$conn);

### ask PHP to tell you the failure reason
if (!$rs) {
  echo 'Query failed because ', mysql_error();
}

### continue with your code
$numRows = nysql_num_rows($rs);
m-productions
I would like to try this out, however i cant beacuse its flash based, and i cant see what it echos back, could you modify that file real fast to add some text filed to it, so i can do it right there on that php file

like just add a text field for user, password, thena submit button.
i tryed doing this on my own, but i just couldnt get it to work =( im an ActionScripter not a php scripter =( i just cant tell why this dosnt work!! theres no reason for it not to, none!



EDIT: UMMM WOW, i got it to work, heres the thing...... $username dosnt work....if i name it $usernam or $usernamee (anything other than $username) it works....why!?!!??!
hexkid
I have no idea how to integrate PHP and flash. If you want to put the echo in a variable do this
Code:
### echo 'Query failed because ', mysql_error();
$variable = 'Query failed because ' . mysql_query();


Now you can use $variable for whatever you want. If I wanted to put it in a HTML input field, I'd do
Code:
<!-- in HTML mode -->
<form action="whatever.php" method="post">
<input type="text" name="error" value="<?php echo $variable; ?>"><br>
<input type="submit">
</form>



--------
Not using $username only appears to work. What happens, when the user enters USERNAME for the username and PASSWORD for the password, is that the SQL will become
Code:
select * from table where username='' and password='PASSWORD'
Related topics
PHP login/logout problem
PHP Login Problem
php+mysql password / login screen
I am trying to build a contact form using php and flash
my first php login w/o database
Flex + PHP login
PHP or Flash Poll/Voting script
MSN network php login?
Frih$ on offer for PHP Login System
PHP login script problem
Free php script login / register , GREAT!
PHP Login Sessions & Security with Frihost
Simple PHP Login Script
Php login
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.