 |
 |
 |
 |
July 3rd, 2005, 07:20 AM
|
#1
|
|
Registered User
Join Date: Jul 2005
Location: Athens/Greece
Posts: 10
|
Variable Load in PHP 5.0.2
Hello to all,
i have a question about the arrays $_POST and $_HTTP_POST_VARS
which one can i use in PHP v5.0.2 so that i can load variables from other applications?
I have Apache XAMPP Lite version 1.4.8 in my PC installed.
The thing is that i like to load some variables from a .swf file (Flash MX) and then save them in a databank. It doesn't work! 
The MySql-skript is allright and works (i have allready double checked it). In this vesrion of apache is PHPMyAdmin 2.5.7 pl1 installed too.
Here is my PHP-MySql code:
PHP Code:
<? //First of all the load of variables from the .swf file (is here the //problem???) $VarA = $HTTP_POST_VARS['Var1']; $VarB = $HTTP_POST_VARS['Var2']; $VarC = $HTTP_POST_VARS['Var3']; $VarD = $HTTP_POST_VARS['Var4']; $VarE = $HTTP_POST_VARS['Var5']; //Connect to the databank network_quiz $conn_id = mysql_connect("localhost","root",""); $db_con = mysql_select_db("Network_Quiz",$conn_id); //Open table and save the data into it $data_save = "INSERT INTO Data_from_flash VALUES('".$VarA."','".$VarB."','".$VarC."','".$VarD."','".$VarE."')"; $result = mysql_query($data_save); //close the connection mysql_close($db); ?>
I have this problem for long time now and in other forums noone could help...I wish i can find someone in webmasterlingo!
thank you,
spacerom
Last edited by spacerom : July 3rd, 2005 at 07:23 AM.
|
|
|
July 3rd, 2005, 07:50 AM
|
#2
|
|
PHP addict
Join Date: Dec 2003
Location: Russia, Nizhny Novgorod
Posts: 71
|
You should use $_POST array for POST data and $_REQUEST array for all request data (GET, POST). $HTTP_POST_VARS is depreciated in versions 4.3.0 and higher.
__________________
God is real, unless declared as integer
|
|
|
July 3rd, 2005, 09:35 AM
|
#3
|
|
Registered User
Join Date: Jul 2005
Location: Athens/Greece
Posts: 10
|
well, i just did that i tried this too hier is the code, i use the POST method for the transfer.
Code:
PHP Code:
<?
//first of all the load of variables from the .swf file (is here the problem???)
$VarA = $_POST['Var1']; $VarB = $_POST['Var2']; $VarC = $_POST['Var3']; $VarD = $_POST['Var4']; $VarE = $_POST['Var5'];
//connect to my databank "Network_Quiz"
$conn_id = mysql_connect("localhost","root",""); $db_con = mysql_select_db("Network_Quiz",$conn_id);
// Open table and save the data into it $data_save = "INSERT INTO Data_from_flash VALUES('".$VarA."','".$VarB."','".$VarC."','".$VarD."','".$VarE."')";
$result = mysql_query($data_save);
// close the connection
mysql_close($db);
?>
Do u think there is something else i should do, maybe the server is not ok? I don't have such much experience on server skripting 
|
|
|
July 3rd, 2005, 11:10 AM
|
#4
|
|
PHP addict
Join Date: Dec 2003
Location: Russia, Nizhny Novgorod
Posts: 71
|
I used the following snippet to check that the PHP part of your script works fine:
PHP Code:
<html>
<?php
$VarA = $_POST['Var1'];
$VarB = $_POST['Var2'];
$VarC = $_POST['Var3'];
$VarD = $_POST['Var4'];
$VarE = $_POST['Var5'];
$data_save = "INSERT INTO Data_from_flash
VALUES('".$VarA."','".$VarB."','".$VarC."','".$VarD."','".$VarE."')";
echo $data_save;
?>
<form method=post action=test.php>
<input type=hidden name=Var1 value=test1>
<input type=hidden name=Var2 value=test2>
<input type=hidden name=Var3 value=test3>
<input type=hidden name=Var4 value=test4>
<input type=hidden name=Var5 value=test5>
<input type=submit>
</form>
</html>
So, probably, you have an error in the Flash-part, it does not submit the form data properly or you have mistyped form names (Var1 / VarA) for example. Use following snippet instead your code to check what does your flash actually submit to the script:
PHP Code:
<?php
echo "<pre>";
print_r($_POST);
print_r($_GET);
echo "</pre>";
?>
__________________
God is real, unless declared as integer
|
|
|
July 4th, 2005, 07:02 AM
|
#5
|
|
Registered User
Join Date: Jul 2005
Location: Athens/Greece
Posts: 10
|
I dont know if its allowed btu take a look in the actionscript code:
//The code for the load of variables in from swf to php
on (release) {
if (!Personal_Nr.length) { //Text variable
Kontakt_Status = "Please give your Pnr"; //Text Variable
} else if (!Firstname.length) { //Text variable
Kontakt_Status = "Please enter your first name";
} else if (!Name.length) { //Text variable
Kontakt_Status = "Please enter your second name";
} else {
SendVar = new LoadVars();
SendVar.Var1 = Personal_Nr; //Personal_Nr is the first variable to load in php
SendVar.Var2 = Firstname;
SendVar.Var3 = Name;
SendVar.Var4 = Points;
LoadVar = new LoadVars();
SendVar.sendAndLoad("DatabankConn.php",LoadVar, "POST");
Kontakt_Status = "Data were sent!";
gotoAndStop("End");
}
}
I think you agree that all is ok.....BUT!! BUT!! BUT!! f****
I will try the second suggestion but ....man!....i try this for a week or so...
|
|
|
July 4th, 2005, 11:13 AM
|
#6
|
|
PHP addict
Join Date: Dec 2003
Location: Russia, Nizhny Novgorod
Posts: 71
|
He-he, of course that is allowed, but mind you, I don't know ActionScript; I have hacked on some Flash forms, but never tried to make one myself. I have attached the source of a simple Flash poll which generates the following query, I think you just need something like that:
Code:
Post array (
'risposte' => 'Yo?!,1,2,3,4',
'y' => '129.6',
'h' => '33.6',
'i' => '5',
'myrisp' => '_level0.myrisposta4',
'miovoto' => 'risposta4',
'Submit' => 'vota',
)
Try the second snippet to find out what actually does your SWF submit if any...
Or post your compiled Flash file so I can try that out myself.
__________________
God is real, unless declared as integer
|
|
|
July 10th, 2005, 05:48 PM
|
#7
|
|
Registered User
Join Date: Jul 2005
Location: Athens/Greece
Posts: 10
|
Well i didn't understand much from your last script, you sent this array to php,with your fla file i didn't have luck either because you didn't upload the php document. 
Well, here is the .fla file and the .php file. Afraid to say that it still doesn't work....If you are interested and find something please tell me.
|
|
|
July 12th, 2005, 01:21 AM
|
#8
|
|
Registered User
Join Date: May 2004
Posts: 70
|
From what I've tested, the variables should work fine but theres a problem in your actionscript. You have the Text Box and Length Check listing the first box as Pnr but then when you send the variable you put in "SendVar.Var1 = Personal_Nr;" which should be "SendVar.Var1 = Pnr;" to send the variable correctly. This variable not being sent may be what was messing up your php as well, try changing it and let me now if it works or not.
Also double check all you capital letters and make sure it all matchs up, most stuff in coding is case sensitive so the table name "Data_from_flash" and "data_from_flash" are considered different and will throw an error, double check it all.
|
|
|
July 12th, 2005, 05:40 AM
|
#9
|
|
Registered User
Join Date: Jul 2005
Location: Athens/Greece
Posts: 10
|
Yes you were right, i renamed the variable, i tried once more...nothing!! Man!!
I just tried and double checked (not only double but triple checked) the letters and the capitals in all my data, everything looks fine...
Do u have other suggestions? Maybe for the PHP-Document?
spacerom
|
|
|
July 12th, 2005, 11:53 AM
|
#10
|
|
Registered User
Join Date: May 2004
Posts: 70
|
Can you post a table export for the MySQL so that I can try exactly what you are doing with the same table and all and you arent using this exact php script you posted are you? You change the MySQL connect to include your username/password in yours correct?
Try using this
Code:
<?
//first of all the load of variables from the .swf file (is here the problem???)
$VarA = $_POST['Var1'];
$VarB = $_POST['Var2'];
$VarC = $_POST['Var3'];
//connect to my databank "Network_Quiz"
$conn_id = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error());
$db_con = mysql_select_db("Network_Quiz",$conn_id) or die('Could not select database');
// Open table and save the data into it
$data_save = "INSERT INTO Data_from_flash VALUES('".$VarA."','".$VarB."','".$VarC."')";
$result = mysql_query($data_save) or die('Query failed: ' . mysql_error());
// close the connection
mysql_close($db);
?>
and replace the connection line with your user/pass for MySQL then navigate to the PHP page itself, if its error is that it can't connect/select db or put in the string it will throw an error to the page saying which one.
Last edited by Marshall : July 12th, 2005 at 12:03 PM.
|
|
|
July 16th, 2005, 09:27 AM
|
#11
|
|
Registered User
Join Date: Jul 2005
Location: Athens/Greece
Posts: 10
|
Yes that is a nice way too (with "die"), but in Dreamweaver you get a debugger from default...but i tried your suggestion too and it still doesn't work....Not together with Flash MX
Well in this version of Apache that i have i don't need to give a username and password so that i can enter the database...
So username is "localhost" and if you want to be sure for the password you give "root". That's what i did...
The thing is that when i use it with Dreamweaver and normal variable attributes (for example i give: $VarA = 52627;, $VarB = "John"; etc.) then the php-mysql script works just fine and the variables are loaded in the databank!!
But not when i use the script together with Flash MX... So i figured out that it can not load the flash-variables in the php script and then to my databank...
I get no response and no variables are loaded in the databank
In the attachment you can find the two scripts (php and actionscript) and beside that you can see how i want to build the databank in an excel document.
Thank you if you can help.
spacerom
|
|
|
July 16th, 2005, 01:43 PM
|
#12
|
|
Registered User
Join Date: Jul 2005
Posts: 7
|
Hi, Spacerom
Have you tried posting in Apache friends about the problem?
|
|
|
July 17th, 2005, 06:25 AM
|
#13
|
|
Registered User
Join Date: Jul 2005
Location: Athens/Greece
Posts: 10
|
I don't know if they can help...I don't think there is a problem with my Apache server...It simply cannot load the variables from the .swf file....But when it comes to the server it's ok, i have test it with dreamweaver and it works fine...
|
|
|
July 17th, 2005, 12:36 PM
|
#14
|
|
Registered User
Join Date: Jul 2005
Posts: 7
|
Well I had a problem once with PHP when I tried XAMP and they were able to fix it.
Good Luck
|
|
|
August 31st, 2005, 06:25 AM
|
#15
|
|
Registered User
Join Date: Aug 2005
Posts: 16
|
if u wanna know what's the error exactly u can use this code
if(!($results = mysql_query( $data_save,$conn_id))) {
outError(sprintf("the error is %d %s ", mysql_errno ($data_save),mysql_error($data_save)));
exit();
}
and the fuction of outError is:
function outError($errorMsg){
printf("<br> %s \n",$errorMsg);
}
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 01:46 PM.
|
|
 |
 |
 |
 |
|