Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flash doesn't submit data to mySql

Status
Not open for further replies.

DaSe

Programmer
Feb 14, 2008
149
GB
Hi guys...
I have a simple Flash and PHP registration code with database set up locally on 'wamp'.Database works absolutely fine on a local system. However when I try to submit a simple registration from Flash it doesn't send anything at all. Here are 2 files to look at. Any ideas ? Regards.

Code:
<?php
require_once('conf.inc.php');
require_once('functions.php');
// ---
// register new user
//


function register($username,$pass,$email,$question,$answer)
{
  
  
   GLOBAL $db, $table;
   $username = trim($username);
   $pass = trim($pass);
   $email = trim($email);
   $question = addslashes(trim($question));
   $answer = addslashes(trim($answer));
   $validEmail = valid_email($email);
   $validName = valid_userName($username);
   $validPass = valid_password($pass);
   if(!$validName) return "error=invalid name";
   if(!$validPass) return "error=invalid password";
   if(!$validEmail) return "error=invalid email";
   $pass = md5(trim($pass));
   // all checks ok
   $query = mysql_query("INSERT INTO $table(userName,userPassword,userMail,userQuestion,userAnswer) VALUES 
   ('$username','$pass','$email','$question','$answer')");
 
   if(!$query)
   {
      return "error=" . mysql_error();
   } else {
      return "user=ok";

   }
   
   
}

?>

And Flash one:

Code:
on (release) {
	errorMsg.text = ''
	if((userName.length > 7 &&  userName.length < 16)
			&& (userPassword.text == userPassword2.text)
			&& (userPassword.length > 5 && userPassword.length < 9)
			&& (userMail.length > 0)
			&& (secretQuestion.length > 0)
			&& (secretAnswer.length > 0))
	{
			var regVars = new LoadVars();
			regVars.action = 'register';
			regVars.username = userName.text;
			regVars.pass = userPassword.text;
			regVars.email = userMail.text;
			regVars.question = secretQuestion.text;
			regVars.answer = secretAnswer.text;
			regVars.sendAndLoad(php_file, regVars,'POST');
			registerBtn.enabled = false;
			regVars.onLoad = function()
			{
				if(this.error != undefined)
				{
					errorMsg.text = this.error;
				} else {
					_root.gotoAndStop('new_ok');
				}
				registerBtn.enabled = true;				
			}
	}

}

 
I think there's a problem with the switch statement. It uses $HTTP_POST_VARS. But it still doesn't work when I tried to substitute $HTTP_POST_VARS with $_POST. Here is user.php's rest of the code.
Code:
<?php
include('conf.inc.php');
require_once('functions.php');
// ---
// register new user
//


function register($username,$pass,$email,$question,$answer)
{
  
   
   GLOBAL $db, $table;
   $username = trim($username);
   $pass = trim($pass);
   $email = trim($email);
   $question = addslashes(trim($question));
   $answer = addslashes(trim($answer));
   $validEmail = valid_email($email);
   $validName = valid_userName($username);
   $validPass = valid_password($pass);
   if(!$validName) return "error=invalid name";
   if(!$validPass) return "error=invalid password";
   if(!$validEmail) return "error=invalid email";
   $pass = md5(trim($pass));
   // all checks ok
   $query = mysql_query("INSERT INTO $table(userName,userPassword,userMail,userQuestion,userAnswer) VALUES 
   ('$username','$pass','$email','$question','$answer')");
 
   if(!$query)
   {
      return "error=" . mysql_error();
   } else {
      return "user=ok";

   }
   
   
}

?>
<?php
// ---
// login, check user
// ---
function login($username,$pass)
{
   GLOBAL $db,$table;
   $username = trim($username);
   $pass = md5(trim($pass));
   $query = mysql_query("SELECT * FROM $table WHERE userName = '$username' AND userPassword = '$pass'");
   return mysql_num_rows($query);
}

// ---
// forget password
// ---
function forget($email)
{
   GLOBAL $db,$table;
   $email = trim($email);
   $query = mysql_query("SELECT userName, userQuestion from $table WHERE userMail = '$email'");
   if(mysql_num_rows($query)<1)
   {
      return "error=email not present into database";
   }
   $row = mysql_fetch_array($query);
   return "userName=$row[userName]&userQuestion=" . stripslashes($row['userQuestion']);
}

// ---
// generate new password
// ---
function new_password($username,$email,$answer)
{
   GLOBAL $db,$table;
   $username = trim($username);
   $email = trim($email);
   $answer = addslashes(trim($answer));
   $query = mysql_query("SELECT * FROM $table WHERE userName = '$username' AND userMail = '$email' AND userAnswer = '$answer'");
   if(mysql_num_rows($query) < 1)
   {
      return "error=wrong answer";
   }
   $rand_string = '';
   // ---
   // generating a random 8 chars lenght password
   // ---
   for($a=0;$a<7;$a++)
   {
      do
      {
         $newrand = chr(rand(0,256));
      } while(!eregi("^[a-z0-9]$",$newrand));
      $rand_string .= $newrand;
   }
   $pwd_to_insert = md5($rand_string);
   $new_query = mysql_query("UPDATE $table SET userPassword = '$pwd_to_insert' WHERE userName = '$username' AND userMail = '$email'");
   if(!$new_query)
   {
      return "error=unable to update value";
   }
   return "userName=$username&new_pass=$rand_string";
}

// ---
// decisional switch
// ---
if(isset($HTTP_POST_VARS["action"]))
{
   switch($HTTP_POST_VARS["action"])
   {
      case "register":
         $result = register($HTTP_POST_VARS['username'],$HTTP_POST_VARS['pass'],$HTTP_POST_VARS['email'],$HTTP_POST_VARS['question'],$HTTP_POST_VARS['answer']);
         print $result;
         break;
      case "login":
         $result = login($HTTP_POST_VARS['username'],$HTTP_POST_VARS['pass']);
         print "user=" . $result;
         break;
      case "forget":
         $result = forget($HTTP_POST_VARS['email']);
         print $result;
         break;
      case "new_password":
         $result = new_password($HTTP_POST_VARS['username'],$HTTP_POST_VARS['email'],$HTTP_POST_VARS['answer']);
         print $result;
         break;
   }
}

?>
 
What, if any, are the values of the vars being received by the PHP script? Once you are sure the correct vars are being received then you can run the script directly and trace the error.

Keith
 
I've checked it - looks like script is not receiving any vars. I had used a Flash/PHP chat before and communication was fine. I also tried to change $HTTP_POST_VARS...and to no avail..
 
Is the script being called?
Write some junk into a log file to see if the script is being accessed.

I am not familiar with sendAndLoad as I usually use the LoadVars method instead. I don't know which is actually the best but LoadVars works great in 2 way data passing.

Keith
 
Hi...
Ok - the reason was '$_POST' was not working generally at all on wamp although all other services were working fine. After installing Xampp - $_POST variable works ok. Still the code doesn't submit anything. I'll be trying writing a different form including LoadVars and see if that works locally..Regards.
 
Hi guys...just a simple form. The var $_POST doesn't receive and sendAndLoad() doesn't seem to work at on localhost. I'd to get it worked on localhost. I don't think there is anything wrong in the codes whatsoever ?

Code:
PHP
---

<?php
include ("connections/conn.php");


$user = $_POST['user'];
$in  = mysql_query("INSERT INTO auth (userName) VALUES ('$user')");
?>

..and AS2:

Code:
on (release) {
	

var register:LoadVars = new LoadVars();
register.user = userName.text;
register.sendAndLoad("C:/xampp/htdocs/tests/user.php" , register , "POST");
}

The above submit to database only 'undefined'. It doesn't submit anything from input text (userName) to database.
 
Thank you guys...finally made it working on 'xampp'...seems there's a problem with $_POST variables in 'wamp' ( although all services are have been working fine ). Regards.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top