Developing Flash/Database interaction using Dreamweaver. Pt I: User Authentication (updated) Support Product Page

This topic was archived

Problems setting up

Reported 20 Jan 2005 02:32:40
1
has this problem
20 Jan 2005 02:32:40 Chad Mr. posted:
I dloaded your tutorial, and completed all task. The problem im having is, that it is doing absolutely nothing. You can see it at www.actionfx.net/php/login.html
Is there soppose to be an action on the login button?

Replies

Replied 20 Jan 2005 02:54:15
20 Jan 2005 02:54:15 Chad Mr. replied:
When I test the movie I get this error

file:///
C|/Documents%20and%20Settings/Chad/My%20Documents/Flash%5FAgent/login.swf
Replied 25 Jan 2005 20:39:52
25 Jan 2005 20:39:52 Alex July replied:
Sorry for the belated reply Chad. Yes there is an action for the log-in button. This is described in the tutorial.
Also the line you are getting in the Output window is not and error but an output of the trace() action revealing the location of your file on your hard drive:

"The following line will output your "_root._url" when you test your movie in Flash.
Copy and paste it to replace the current value.

trace(_root._url)"

This means that you have to substitue the value in the validateRequest() function (first frame of Actions layer) with with the one you see in the Output window, like this:

function validateRequest(){
if(_root._url!="file:///C|/Documents%20and%20Settings/Chad/My%20Documents/Flash%5FAgent/login.swf" || loginInfo.validuser != "1"{
gotoAndStop(1);
}
}
Replied 25 Jan 2005 23:33:18
25 Jan 2005 23:33:18 Chad Mr. replied:
I read the through the tutorial 4 times, and the only thing that refers to the button is in the actionscript layer. Is that what you were referring to?

Also..this is my php code complete. My database is actionfx_net , connection name is actionfx. Do see anything wront with my php document?

<pre id=code><font face=courier size=2 id=code>validuser=&lt;?php echo $totalRows_Recordset1 ?&gt;
&lt;?php require_once('Connections/actionfx.php'); ?&gt;
&lt;?php
$colname_Recordset1 = "1";
if (isset($_POST['USER_ID'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_POST['USER_ID'] : addslashes($_POST['USER_ID']);
}
$colname2_Recordset1 = "1";
if (isset($_POST['PASSWORD'])) {
$colname2_Recordset1 = (get_magic_quotes_gpc()) ? $_POST['PASSWORD'] : addslashes($_POST['PASSWORD']);
}
mysql_select_db($database_actionfx, $actionfx);
$query_Recordset1 = sprintf("SELECT * FROM users WHERE USER_ID = %s AND users.PASSWORD=%s", $colname_Recordset1,$colname2_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $actionfx) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

mysql_free_result($Recordset1);
?&gt;
</font id=code></pre id=code>

Edited by - cnl83 on 25 Jan 2005 23:41:11
Replied 25 Jan 2005 23:43:22
25 Jan 2005 23:43:22 Alex July replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
I read the through the tutorial 4 times, and the only thing that refers to the button is in the actionscript layer. Is that what you were referring to?
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

Chad, here is the quote from the article:

/*Use addEventListener method to trigger the authentication function when the Log-in button is clicked
*/
Login_btn.addEventListener("click", loginUser);


/*Define validation function which checks the value of the validuser variable as well as readonly _url property of the Flash movie. Note that this value is hardcoded (!!!)and will be different on your machine. It is an additional security step to ensure that the movie can not be run from any location other then your web server.
The following line will output your "_root._url" when you test your movie in Flash.
Copy and paste it to replace the current value.
*/
trace(_root._url)


function validateRequest(){
if(_root._url!="file:///C|/Documents%20and%20Settings/localuser/My%20Documents/flash_agent/flash%5Fagent.swf" || loginInfo.validuser != "1"{
gotoAndStop(1);
}
}

I hope this helps
Replied 25 Jan 2005 23:57:25
25 Jan 2005 23:57:25 Alex July replied:
Sorry Chad, about your PHP code, yes there is an ERROR!

Here the code that I have in the arctilce:
&lt;?php require_once('Connections/flash_agent.php'); ?&gt;
&lt;?php
$colname2_userLogin_rs = "1";
if (isset($_POST['PASSWORD'])) {
$colname2_userLogin_rs = (get_magic_quotes_gpc()) ? $_POST['PASSWORD'] : addslashes($_POST['PASSWORD']);
}
$colname_userLogin_rs = "1";
if (isset($_POST['USER_NAME'])) {
$colname_userLogin_rs = (get_magic_quotes_gpc()) ? $_POST['USER_NAME'] : addslashes($_POST['USER_NAME']);
}
mysql_select_db($database_flash_agent, $flash_agent);
$query_userLogin_rs = sprintf("SELECT * FROM users WHERE USER_NAME = '%s' AND users.PASSWORD='%s'", $colname_userLogin_rs,$colname2_userLogin_rs);
$userLogin_rs = mysql_query($query_userLogin_rs, $flash_agent) or die(mysql_error());
$row_userLogin_rs = mysql_fetch_assoc($userLogin_rs);
$totalRows_userLogin_rs = mysql_num_rows($userLogin_rs);
?&gt;
validuser=&lt;?php echo $totalRows_userLogin_rs ?&gt;
&lt;?php
mysql_free_result($userLogin_rs);
?&gt;


The validuser=&lt;?php echo $totalRows_userLogin_rs ?&gt; string should go right before

&lt;?php
mysql_free_result($userLogin_rs);
?&gt;

but not at the beginnning of the script as you have.

But you shouldn't worry about the code if you follow all the steps correctly.
AFTER you create the Recordset you have to (as it's described in the aricle):

We are almost done. Looking at your web page switch to the Design view and type validuser= (" validuser" is the name of the variable Flash is expecting to "see".

Insert the cursor right after "=", hit the "+" button in the Server Behaviors panel and select Display Record count -&gt; Display Total records behavior. Click OK in the pop-up dialog box to confirm that you want to use the "userLogin_rs" Recordset for this purpose.

This will output the total number of rowsof data returned from the database. The expected value is "1" which means the match has been found. Logically if it outputs "0" then the combination does not exist and the user cannot be authenticated.


If you follow the steps in the correct order the validuser= string will go in the right spot
Replied 26 Jan 2005 00:36:22
26 Jan 2005 00:36:22 Chad Mr. replied:
Ok I went back and re-followed the tutorial, and I got it right this time. I uploaded it to my
server, and I still have nothing. Here is my php code.

<pre id=code><font face=courier size=2 id=code>&lt;?php require_once('Connections/actionfx.php'); ?&gt;
&lt;?php
$colname_userLogin_rs = "1";
if (isset($_POST['USER_ID'])) {
$colname_userLogin_rs = (get_magic_quotes_gpc()) ? $_POST['USER_ID'] : addslashes($_POST['USER_ID']);
}
$colname2_userLogin_rs = "1";
if (isset($_POST['PASSWORD'])) {
$colname2_userLogin_rs = (get_magic_quotes_gpc()) ? $_POST['PASSWORD'] : addslashes($_POST['PASSWORD']);
}
mysql_select_db($database_actionfx, $actionfx);
$query_userLogin_rs = sprintf("SELECT * FROM users WHERE USER_ID = %s AND users.PASSWORD = %s", $colname_userLogin_rs,$colname2_userLogin_rs);
$userLogin_rs = mysql_query($query_userLogin_rs, $actionfx) or die(mysql_error());
$row_userLogin_rs = mysql_fetch_assoc($userLogin_rs);
$totalRows_userLogin_rs = mysql_num_rows($userLogin_rs);
?&gt;
validuser=&lt;?php echo $totalRows_userLogin_rs ?&gt;
&lt;?php
mysql_free_result($userLogin_rs);
?&gt;
</font id=code></pre id=code>

In Flash the
function validateRequest(){
if(_root._url!="file:///C|/Documents.....

shouldnt that be something else if im uploading it to a web server?
Replied 26 Jan 2005 00:49:28
26 Jan 2005 00:49:28 Alex July replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>

shouldnt that be something else if im uploading it to a web server?
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>


Of course it should Chad. You are changing the location of your file, so the location check variable should reflex this change. It should contain the full url to your flash movie.

For learning perposes however I would really suggest to run the application locally (through the localhost/yousitename as _global.basehref) as it is easier to debug -when you test the application is Flash (Ctrl+Enter). Say you haven't set up the database properly or haven't uploaded the php file - you would see a connection error in the Output window in Flash. Otherwise you won't know what goes wrong and I won't be able to tell you.
Replied 26 Jan 2005 00:58:35
26 Jan 2005 00:58:35 Chad Mr. replied:
I changed it and still got nothing www.actionfx.net/php
I will setup a local server, and try that as requested. I will post here once I have done so.
Replied 26 Jan 2005 01:01:27
26 Jan 2005 01:01:27 Alex July replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
I changed it and still got nothing www.actionfx.net/php
I will setup a local server, and try that as requested. I will post here once I have done so.
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

Can you send me the source file (fla) ? I can test it on my end in Flash
Replied 26 Jan 2005 01:08:33
26 Jan 2005 01:08:33 Chad Mr. replied:
Replied 26 Jan 2005 01:54:40
26 Jan 2005 01:54:40 Alex July replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
www.actionfx.net/php/getin.zip
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

Chad, you have made a few errors in both Flash and Dreamweaver.
First in Flash you have:

if(_root._url!="www.actionfx.net/php/flash_Fagent.swf"

what's flash_Fagent.swf? <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
The name of your movie on the server is flash_agent.swf

Next in Dreamweaver you have used USER_ID istead of PASSWORD and PASSWORD instead of USER_NAME (it's USER_NAME not USER_ID by the way).

This is where the major mixup has bigun.

As the result this is the line 12 from your code:
$query_userLogin_rs = sprintf("SELECT * FROM users WHERE USER_ID = %s AND users.PASSWORD = %s", $colname_userLogin_rs,$colname2_userLogin_rs);


and this is line 12 from mine:
$query_userLogin_rs = sprintf("SELECT * FROM users WHERE USER_NAME = '%s' AND users.PASSWORD='%s'", $colname_userLogin_rs,$colname2_userLogin_rs);

USER_ID column IS a Number data type column. That's why your Dreamweaver correclty didn't insert single quotes around the parameter - because it knows it's a Number (USER_NAME = '%s' in my code and USER_ID = %s in yours -see no quotes around %s in your code) .

Then , following my aritcle you copied the pattern to the password so it thinks again that it's a Number type of data that is being requested by the user, while in fact is't a String.

Again you wouldn't have to worry about it if you really followed the steps described to the letter as Dreamweaver keeping trace of all this in the backround.

Try this - first fix the geting.php file by following all the steps and selecting the correct columns.
Then make sure the database entries are in place (there is USER_NAME and PASSWORD in the database).

I have changed the "_global.basehref" variable in the file you sent me so you can test your remote application from your computer in Flash. I even changed the Flash movie path so it matches the one you have on your hard drive. Simply get the file here and examine the code:
www.linecraft.com/flash_agent.fla

While testing your file in Flash i got a "message" from the php page describing the error - this is how I figured out what was done wrong.

Reply to this topic