Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with writing variables to file

Status
Not open for further replies.

MrKovacic

IS-IT--Management
Nov 5, 2002
213
US
I have 3 parts to the full project, one flash file, one PHP file, and a txt file that is created by the php file.

Here is the code for the php file:
Code:
<?
$filename = "chat.txt";
$name = stripslashes($name);
$message = stripslashes($message);
$Created="Ecard Created on $Today";
$EcardNum = $EcardSelect;
$Text = "$name says $message";
$fp = fopen( "./txt/$filename","w"); 
fwrite($fp, $Text, 10000); 
fclose( $fp ); 
?>

for the inputs, I put 'Mike' as name and 'Hello World' as the message. When I submit this through the test flash interface, the text file comes out with this example...

Code:
Mike says


and that it. Is there somthign goofy in my coding?

Thanks in advance!

Thank you!!!

Mike Kovacic

&quot;&quot;&quot; &quot;&quot;&quot;
(o) (O)
\____/
 
How are you submitting the form, post or get method? While it does not look like it will help in your case, I suggest you do not rely on register globals being on (what you currently do) but rather use on of the superglobals ($_GET, $_POST) to grab the submitted values. I suggest you put the code:
Code:
echo '<pre>';
print_r ($_POST); // or $_GET if you are using the get method
echo '</pre>';
to determine what values have been submitted. It could be the deal with different case in spelling of message. Anyway, this will help you debug the code easier.
 
Actually, I am using Flashs Actionscripting to submit the script..

Here is that script:

This is an action on a button
Code:
on (release) {
	loadVariablesNum ("SendEcard.php", 0, "POST");
	gotoAndPlay (2);
}

Thank you!!!

Mike Kovacic

&quot;&quot;&quot; &quot;&quot;&quot;
(o) (O)
\____/
 
Your code still does not show you accessing anything to get the variables $name and $message which means that you are relying on global variables. Your method looks to be POST so at the top of your code you should have something to the extent of
Code:
$name = $_POST['name'];
$message = $_POST['message'];
Global variables should be off by default as well as it can lead to unpredictable problems and security risks.
 
looks like I got it to work. Now I just need the Flash side to read the file..

Here is the code that is working properly.. But this time I am using PHP form to submit the data instead of flash which is actually the way I want it :)

Code:
<?php
$emailAddress = $_POST['emailadd'];

if(!$emailAddress) // If email address is not entered show error message
{
    echo "Enter some text.";
    exit;
}
else
{
    $filename = "./txt/chat.txt"; // File which holds all data
    $content = "text=$emailAddress\n"; // Content to write in the data file
    $fp = fopen($filename, "a"); // Open the data file, file points at the end of file
    $fw = fwrite( $fp, $content ); // Write the content on the file
    fclose( $fp ); // Close the file after writing
    
    if(!$fw) echo "Couldn't write the entry.";
    else echo "Successfully wrote to the file.";
}
?>

Now I am off to the flash forums to get my variables to read properly.

THANX TO ALL!!

Thank you!!!

Mike Kovacic

&quot;&quot;&quot; &quot;&quot;&quot;
(o) (O)
\____/
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top