PDA

View Full Version : PHP woes -> php to Flash



Raziel
February 4th, 2005, 07:44 AM
Hi, i'm building a nickname checker in flash to see if a nickname is available but i'm getting undefined returned in the fields.

here's my code

<?php
$usr_name = $_POST['user'];

$hostname_DB_conn = "localhost";
$database_DB_conn = "db";
$username_DB_conn = "test";
$password_DB_conn = "12345";
$DB_conn = mysql_pconnect($hostname_DB_conn, $username_DB_conn, $password_DB_conn) or trigger_error(mysql_error(),E_USER_ERROR);



mysql_select_db($database_DB_conn, $DB_conn);
$query_findUser = sprintf("SELECT * FROM banner_usr WHERE usr_name = %s", $colname_findUser);
$findUser = mysql_query($query_findUser, $DB_conn) or die(mysql_error());
while($res = mysql_fetch_array($findUser)) {
if($res->usr_name==$usr_name) {
echo "&returnVal=Sorry, de gebruikers naam bestaat al";
}else{
echo "&returnVal=Yay ! hijs vrij !";
}
}

?>

iloveitaly
February 4th, 2005, 07:56 AM
what does your flash code look like?

Raziel
February 4th, 2005, 08:26 AM
stop();
//=================================
// INIT
//=================================
lvOut = new LoadVars(); //create lv object
lvIn = new LoadVars(); //create lv object
lvIn.onLoad = function (success) {
if(success){
output.text = lvIn.returnVal;//PHP variable value to textbox
}else{
output.text = "fail"; //or notify of failure
}
}
//=================================
// BTN
//=================================
myBtn.onRelease = function(){
lvOut.years = years.text; //assign user-input value to lv property called years
//lvOut.send(path + "dogyears.php","_blank"); //send to a blank window
lvOut.sendAndLoad("dog_years.php", lvIn, "POST"); //get results returned to lvIn
};

Raziel
February 4th, 2005, 08:27 AM
i fiddled around a bit with the php and made this, nowit gives me back User found each time


mysql_connect("localhost","test","12345");
mysql_select_db("db");
$search=$_POST["user"];

$result = mysql_query("SELECT * FROM banner_usr WHERE usr_name LIKE '%$search%'");
while($r=mysql_fetch_array($result)) {
if($r->usr_name==$search) {
echo "&returnVal=User found";
}else{
echo "&returnVal=User not found";
}
}

?>

Hans Kilian
February 4th, 2005, 02:36 PM
As far as I can see, you never assign the 'user' variable anything in your Flash code. That results in it being blank in your PHP code. And then your SQL ends up looking like this: SELECT * FROM banner_usr WHERE usr_name LIKE '%%', which matches all your users. And then you get 'User found'.

So you need to put something in the 'user' variable in your Flash file. I'm not very experienced with Flash, but I'd guess it should look something like
lvOut.user = "Raziel";
or whatever nick you want to check.

Raziel
February 7th, 2005, 03:50 AM
actually the lvOut.user = years.text that means it takes what ever is enterd in the text field of years and send it as a variable


errrr nm, i see the error :P