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:

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

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.

if it’s every one second, it’s not manually, but you could use setInterval

What do you mean it’s not manually? I’m weak at actionscript. Can you help me out?

if you refresh every one second, it would be automatic, to refresh manually you would need a button that says refresh on it that would refresh it. to do it every one second you could use setInterval, run a search for setInterval, you will find tons of stuff :thumb:

Ah ok. So let me change my words. I want it to refresh automatically without pressing a button.

see ur other thread, that’s how you do it is with setInterval

here r the php scripts. I can;t upload the fla file cuz its too big. Give me your email address and i’ll send it to u over there.

btw, i commented out the old sentences in the php scripts in case u needed them

well I got it to display it, but now it doesn’t show the name, is there any way to just take out the link for the name, and just have it say the name?

yea. in add.php, change this line:


$Input = "<a href=\"mailto:$Email\"><b>$Name</b></a>: $Comments<br><br>";

to this:


$Input = "$Name: $Comments<br><br>";