Guestbook

hi,

tried to follow a tutorial for creating a guestbook in flash. Well, I think i did everything right, but when i test the page, I can’t get the submitted text to display :-\ have rechecked so many times i can0t find the mistake… hope one of you guys would be nice enough to give me a hand and help me find my mistake.
Gave the .fla and .php script along.

Many thanx

show us the code. I can’t download anything. Post the Flash code and the PHP code.

you can have a check at it online at http://www.icttrading.net/korisv2.htm
click on events, and pictures on the bottom

here is the code:

submit button


on (release) {
	if (Name eq "") {
		Status = "Please enter your name";
	} else if (Email eq "") {
		Status = "Please enter email Address";
	} else if (Website eq "") {
		Status = "Please enter the URL to your website";
	} else {
		Submit = "Yes";
		NumHigh = 10;
		NumLow = 0;
		GuestBook = "Processing..   Loading New... ";
		loadVariablesNum("GuestBook.php", 0, "POST");
		Status = "Your entry has been submitted. ";
		gotoAndStop(3);
	}
}


php code:


<?
1)		$Name = ereg_replace("[^A-Za-z0-9 ]", "", $Name);
2)		$Email = ereg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $Email);
3)		$Comments = ereg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $Comments);
4)		$Website = eregi_replace("http://", "", $Website);
5)		$Website = ereg_replace("[^A-Za-z0-9 \@\.\-\/\'\~]", "", $Website);
6)		$Name = stripslashes($Name);
7)		$Email = stripslashes($Email);
8)		$Website = stripslashes($Website);
9)		$Comments = stripslashes($Comments);
10)		if ($Submit == "Yes") {
11)			$filename = "GuestBook.txt";
12)			$fp = fopen( $filename,"r"); 
13)			$OldData = fread($fp, 80000); 
14)			fclose( $fp ); 
15)			$Today = (date ("l dS of F Y ( h:i:s A )",time()));
16)			$Input = "Name: $NameEmail: $Email
 Website: $WebsiteComments:
$CommentsDate: $Today.:::.";
17)			$New = "$Input$OldData";
18)			$fp = fopen( $filename,"w"); 
19)			fwrite($fp, $New, 80000); 
20)			fclose( $fp ); 
21)		}
22)		$filename = "GuestBook.txt";
23)		$fp = fopen( $filename,"r"); 
24)		$Data = fread($fp, 80000); 
25)		fclose( $fp );
26)		$DataArray = split (".:::.", $Data);
27)		$NumEntries = count($DataArray) - 1;
28)		print "&TotalEntries=$NumEntries&NumLow=$NumLow&NumHigh=$NumHigh&Guest Book=";
29)		for ($n = $NumLow; $n <$NumHigh; $n++) {
30)		print $DataArray[$n];
31)			if (!$DataArray[$n]) {
32)			Print "No More entries";
33)			exit;
34)			}
35)		}
 ?>

Do you have the text file CHMODed to the right values?

changed it to 777, wich means i can have data written on it, is it right?

do this, it hsould help… use the $_POST[]; array to catch the variables. I think that might be the problem.

for each variable that you send to the PHP file, do this at the beginning of your PHP script:


$Submit = $_POST['Submit'];

so there is nothing wrong in my .fla? just have to edit this in the php script?

Is there anything written in the text file? if not then that means that the php script isn’t even running at all, which means that its not retrieving the variables, which means you have to do what I said above.

If the text file has anything written in it, then I don’t know I woul dhave to take another look at the code. Did you try what I suggested? that might work… its probably just a problem with the php because:

The newer versions of PHP have global variables turned off, so you need to use the $_POST or $_GET array to grab them from the previous page/swf file.

nothing written on the txt, so ou must be right, it’s surely a problem with the php, i’ll give it a try and let u know

your code should look something like this:


<? 
$Submit = $_POST['Submit'];
$Name = $_POST['Name'];
$Website = $_POST['Website'];
$Email = $_POST['Email'];
//Put the rest of your code under here....


?>

well tried it out, doesn’t seem to work… no data is written on th txt, doubled check, it is write enables, it’s not the txt…

found this info, don’t know if it might help?

With the Release of PHP 4.1.0 Their have been some additional updates that should be taken into consideration for future use of PHP. In previous versions all PHP variables where available in whatever form they came to the script in, and where automatically declared in the script. For example if you sent the script the variable ‘Name’ from Posting the contents of a form, attached to the end of a URL string, from a cookie, as a session variable, etc that variable is/was automatically available for use in the script (as long as register_globals was turned on). With the release of PHP 4.1.0 you will now have to grab the value from a special array variable:

$_GET - contains form variables sent through GET
$_POST - contains form variables sent through POST
$_COOKIE - contains HTTP cookie variables
$_SERVER - contains server variables (e.g., REMOTE_ADDR)
$_ENV - contains the environment variables
$_REQUEST - a merge of the GET variables, POST variables and Cookie variables.
$_SESSION - contains HTTP variables registered by the session module

For example in the above script. Instead of being able to just use the variable ‘Name’ from the Flash form - we would have to use something like - <? $Name = $_POST[“Name”]; … … ?> - Fortunately the above script used in this tutorial still work for now. But it might be a good idea to get into the practice of using the new method. It is also a more secure method of programming with PHP. To learn more visit www.php.net.

your php file is giving me a parse error… can you re-post the PHP code that you currently have. that might be the problem

I already know about that. That is what I mentioned earlier. :slight_smile:


<?
$Submit = $_POST['Submit'];
$Name = $_POST['Name'];
$Website = $_POST['Website'];
$Email = $_POST['Email'];
$Name = ereg_replace("[^A-Za-z0-9 ]", "", $Name);
$Email = ereg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $Email);
$Comments = ereg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $Comments);
$Website = eregi_replace("http://", "", $Website);
$Website = ereg_replace("[^A-Za-z0-9 \@\.\-\/\'\~]", "", $Website);
$Name = stripslashes($Name);
$Email = stripslashes($Email);
$Website = stripslashes($Website);
$Comments = stripslashes($Comments);
if ($Submit == "Yes") {
	$filename = "GuestBook.txt";
	$fp = fopen($filename,"r"); 
	$OldData = fread($fp, 80000); 
	fclose($fp); 
	$Today = (date ("l dS of F Y ( h:i:s A )",time()));
	$Input = "Name: $NameEmail: $Email Website: $WebsiteComments: $CommentsDate: $Today.:::.";
	$New = "$Input$OldData";
	$fp = fopen($filename,"w"); 
	fwrite($fp, $New, 80000); 
	fclose($fp); 
}
$filename = "GuestBook.txt";
$fp = fopen($filename,"r"); 
$Data = fread($fp, 80000); 
fclose($fp);
$DataArray = split (".:::.", $Data);
$NumEntries = count($DataArray) - 1;
print "&TotalEntries=$NumEntries&NumLow=$NumLow&NumHigh=$NumHigh&GuestBook=";
for ($n = $NumLow; $n <$NumHigh; $n++) {
	print $DataArray[$n];
	if (!$DataArray[$n]) {
		Print "No More entries";
		exit;
	}
}
?>

Just copy and paste that code. I don’t know why those number lines were in there (either you put them there, or your editor did) but you can’t have them their. They cause a parse error and that is probably what was causing the problem.

Place Guestbook.php, GuestBook.txt and your SWF file all in the same folder. Make sure that the TEXT file is CHMODed to 777 and you should be all set. it looks like it should work fine.

pasted the code u gave me, now it does write data on the .txt, thx, but it still doesn’t show it live… arrrgg… i’ll check again my fla, there must be a problem there too…