Shoutbox in PHP and Flash

Ok, I’m trying to make a shout box using PHP and Flash, it’s not working though… You can see what I have so far at www.barbdwyer.com/T6 . I don’t know PHP, so I had one of my friends write the script for me, but he doesn’t know Flash, so he couldn’t help me set it up.

in flash, i have the following code on my submit button:

on(press) { 
      getURL ("add.php", "_blank", "POST");
}

i also have this in a frame:

onEnterFrame = function () {
	Name = theName.text;
	Email = theContact.text;
	Comments = theMessage.text;
};

then here’s the PHP scripts.

one called add.php:

<?php

$Name = ereg_replace("[^A-Za-z0-9\<\>]", "", $Name); 
$Email = ereg_replace("[^A-Za-z0-9 \@\.\-\/\'\<\>]", "", $Email); 
$Comments = ereg_replace("[^A-Za-z0-9 \@\.\-\/\'\<\>]", "", $Comments);

$Name = stripslashes($Name); 
$Email = stripslashes($Email); 
$Comments = stripslashes($Comments); 

if ($Submit == "Yes") { 
	$filename = "shoutbox.txt"; 
	$fp = fopen( $filename,"r"); 
	$OldData = fread($fp, 80000); 
	fclose( $fp );
	$Input = "<a href=\"mailto:$Email\"><b>$Name</b></a>: $Comments<br><br>.:::."; 
	$New = "$Input$OldData";
	$fp = fopen( $filename,"w"); 
	fwrite($fp, $New, 80000); 
	fclose( $fp );
	Header("Location: shoutbox.php"); 
} 

?>

one called forum.php:

<?php

$Name = ereg_replace("[^A-Za-z0-9\<\>]", "", $Name); 
$Email = ereg_replace("[^A-Za-z0-9 \@\.\-\/\'\<\>]", "", $Email); 
$Comments = ereg_replace("[^A-Za-z0-9 \@\.\-\/\'\<\>]", "", $Comments);

$Name = stripslashes($Name); 
$Email = stripslashes($Email); 
$Comments = stripslashes($Comments); 

if ($Submit == "Yes") { 
	$filename = "shoutbox.txt"; 
	$fp = fopen( $filename,"r"); 
	$OldData = fread($fp, 80000); 
	fclose( $fp );
	$Input = "<a href=\"mailto:$Email\"><b>$Name</b></a>: $Comments<br><br>.:::."; 
	$New = "$Input$OldData";
	$fp = fopen( $filename,"w"); 
	fwrite($fp, $New, 80000); 
	fclose( $fp );
	Header("Location: index.php"); 
} 

?>
<form name="shoutbox" action="form.php" method="post">
<table align="center" border="0">
  <tr>
    <td>Name:</td>
    <td><input type="text" name="Name"></td>
  </tr>
  <tr>
    <td>Email:</td>
    <td><input type="text" name="Email"></td>
  </tr>
  <tr>
    <td>Message:</td>
    <td colspan="2" align="right">
<textarea name="Comments"></textarea>
<input type="hidden" name="Submit" value="Yes">
    </td>
  </tr>
  <tr>
    <td colspan="2" align="right"><input type="submit" value="Submit"></td>
  </tr>
</table>
</form>

and finally, one called shoutbox.php:

<?php

$filename = "shoutbox.txt"; 
$fp = fopen($filename,"r");
$Data = fread($fp, 80000);
fclose( $fp ); 

$DataArray = split (".:::.", $Data);

//Put in the starting tag and the ending tag number
for ($n = 0; $n < 20; $n++) {
print $DataArray[$n]; 
}

?>

then there is an empty text file called shoutbox.txt

I am completely confused, he told me to make the add.php from the php part of the forum.php, and I know that this worked when it was in HTML, but I got a headache trying to get it to work in flash. Can someone please help, thanks :slight_smile:

You have to use the LoadVars() class to accomplish this (or atleast thats what i think you should use).

On the main timeline on the first frame, do this:
[AS]
var dataSend = new LoadVars();

dataSend.Name = theName.text;
dataSend.Email = theContact.text;
dataSend.Comments = theMessage.text;

[/AS]

Change this on the button
[AS]
on(press) {
getURL (“add.php”, “_blank”, “POST”);
}[/AS]

to this

[AS]
on(press) {
_root.dataSend.send (“add.php”, “_blank”, “POST”);
}[/AS]

That should probably do it. You can do this via a function, but it works both ways.

I’m suspecting you have to change something in the PHP script, but try this out and tell me if it works or not.

thanks, i’ll try that out now :slight_smile:

hmm, didn’t work :frowning:

thanks for trying though

Why is it get url? It should be loadVariablesNum.

this is for the sending, not the recieving

can anyone else try to help, please? thanks again in advance

I apologize for not getting back. I know what the problem is. Will get back to u in a few

OK, thank you

in the php scripts (except the shoutbox.php), add these lines at the top:



$nameReceived = $_POST['Name'];
$emailReceived = $_POST['Email'];
$commentsReceived = $_POST['Comments'];


After doing this, change



$Name = ereg_replace("[^A-Za-z0-9<>]", "", $Name); 
$Email = ereg_replace("[^A-Za-z0-9 @.-/'<>]", "", $Email); 
$Comments = ereg_replace("[^A-Za-z0-9 @.-/'<>]", "", $Comments);


to:



$Name = ereg_replace("[^A-Za-z0-9<>]", "", $nameReceived); 
$Email = ereg_replace("[^A-Za-z0-9 @.-/'<>]", "", $emailReceived); 
$Comments = ereg_replace("[^A-Za-z0-9 @.-/'<>]", "", $commentsReceived);


in both scripts. Hope it works

I’ll try that when I get home, thanks so much for your help :smiley: :thumb:

Hey no problem. Don’t thank me, thank the forum :wink:

And yea, one more thing. Change the $Submit in the if conditions to $_POST[‘Submit’]. If all of this still doesnt work, post the files if u can.

where is this $Submit that you are talking about? in the if statement?

the line after

$Comments = stripslashes($Comments);

I’m sorry about replying late. I keep waiting for the email notification but it seems like it doesnt work all the time

hmm, it still doesn’t work… :frowning:
I’m uploading the files now, thanks again :smiley:

www.barbdwyer.com/T6/site.zip it’s a pretty big filesize, 1.5 mb because it has the .fla in there

what’s the php file supposed to output? did you try running the file outside of flash, just calling it from the browser?

I got it to work. I will post the files in some time. Hope u dont mind the delay

yeah, it all worked with HTML, but it didn’t work when I tried to call it from flash.

thanks hamza :smiley:

That’s why I said, use loadVariablesNum and set it to send using POST. It’s not only for recieving. This method worked so many times for me when I had a shoutbox.

  • Anyone know how I can make my chatroom faster? I need to learn how to refresh manually every 1 second.