I'm crawling through a tutorial on PHP that is supposed to make a page editable by a user. I need this to make it easy for my client to add/remove text.
I was able to get a php page to display text. (My first tutorial!) In this one, I get the following error message:
Parse error: parse error, expecting `','' or `';'' in [...] mypage.php on line 26.
When the server is reading PHP, does it start line numbers from where you announce that PHP is happening after the html header or at the top of the page?
Everywhere where it might be line 26 seems to have one of those punctuations.
If you have eagle magic coding eyes, would you mind having a look at this so I can see what I'm missing?
So, does this mean that when the server error comes up with a line number, it refers to the line number of where the code begins?
Line 1 would be the first 'if' statement?
Due to your sharp acumen, I no longer get the error message. However, I don't get the editable pages yet either.
Is there a way, when you're troubleshooting code, that you look at things? By this I mean, do you do a pass where you check for semicolons, another pass for open and closing quotes, that kind of thing? I don't know the first things about the disciplines of coding. I muddle through, but I'm really curious about the process and being smart about it. With this, and actionscripting, I'm wondering how to be more efficient.
The text in the textfile displays, but I can't edit it. It's not like the one in the example. I've been through it line by line, and I haven't a clue what I could be doing wrong or what to look for. I am grateful for any advice here.
The link to the tutorial is below. It's short, only one page.
Well, I have Studio MX 2004 which besdes Flash MX 2004, includes Dreamweaver MX 2004.
This is a great tool for developing HTML but other lnguages/scripts as weill: PHP, ColdFusion, CSS, XML,...
In this case it was DW's colored code that helped me to find the error (and its line numbers as well).
There are other tools out there, and free ones as well... search.
The exact line depends on the code and the kind of error, but the line numbers in DW are always turned on!
The code works fine!
Go check your text file!
Notice that the the code requests a variable $pw, which you have to passw via POST or GET (once again DW alows you to test this easily with live data view). To test it using GET is also easy outside DW, just append the variable/value pair to the url:
It shows on the page that you edited it! That's very cool.
It works if I append to the URL what you showed.
You are soooooo cool! Thank you.
I'm going to work through the tutorial you sent me. It looks excellent! Thanks. I'll also check out that link.
I have Dreamweaver. I found a PHP tutorial for it on Macromedia.com - to build a Record Store. Unfortunately, I've spent the last five days trying to get MySQL to work on my OS X machine, in order to do the tutorial, but have been painfully unsuccessful with the install. So I'm sorta stuck when it comes to using Dreamweaver for PHP for now.
But I've ordered a book on PHP and Dreamweaver and hope that I'll be able to at least start with that until I can figure out the MySQL install.
You are beyond cool!
Obrigado,
Lee
"It's kind of fun to do the impossible."
- Walt Disney
I'm working on Flash MX, and I think the files from the wonderful looking tutorial you pointed me to are MX 2004 and they are crashing my Flash. Would you resave them in MX if they're saveable??
You've been very generous. I'm reluctant to prevail again, but I'd be enormously grateful.
I wish you the very best week ever. Thanks again for your help above.
Lee
"It's kind of fun to do the impossible."
- Walt Disney
I guess that the files were saved for Flash MX.
Wouldn't it be a Mac/Win thing?
Isn't there something you have to do when opening a file from another platform? Maybe file->open?
They open fine, so I don't think it's the Mac/Win thing. (I'm on a Mac and use the Flash typer that puts a tiny bit of code in the front of a file so it can be read if I can't get something to open. Didn't have to this time. Haven't had to in a while, come to think of it.)
When either file opens, I can read the actionscript, but when I try to get the library to open or try to publish, or try to open the file with the Library open, Flash unexpectedly quits.
I'm guessing now that it's not an MX/MX 2004 thing either, because the same thing happened when I tried to open the files that you saved as MX from 2004 for me. I really appreciate your trying that for me.
It says to "move the button to the stage" in the commented code. When I try to open the library, it crashes. I tried copying the actionscript to another movie, then opening that one's library, and it didn't crash, so there's something going on with the file, and not Flash. (Yay!)
The big mystery for me is whether there's any special code on the button. I'm going to check that out this morning by creating a button in another movie, naming its instance appropriately, and copying the actionscript and seeing if, by sheer luck, it works.
I'd entertain any other suggestions. I really want to nail this tutorial.
I wish you every good fortune. Thanks so much for your help,
Lee
Last edited by Capoeirista; 09-06-2004 at 09:54 AM.
"It's kind of fun to do the impossible."
- Walt Disney
If I put these files on my localhost, I get a textbox that says "an error occurred." Is this because I didn't change GET to POST on the last line of actionscript code?
Also, in my text editor above, I'd like to be able to read the text as html into my page.
If I put " This is plain text. <b>This is bold text.</b>
It doesn't convert to HTML. It shows the tags. Why is that? Is there a way to fix it?
You get another week of good karma points. I hope you have a great day,
Lee
"It's kind of fun to do the impossible."
- Walt Disney
Although you can use GET in the final application, you should use POST.
The test player for Flash MX there is a bug, as it always uses GET.
In MX 2004, it works as expected.
That's not a real problem because the php script contains:
PHP Code:
$myvar = $_REQUEST['myvar'];
which works for both GET and POST
(you could use $_GET or $_POST instead of $_REQUEST, in case you were using GET or POST respectively in Flash)
Make sure you have the correct url to yor local server, correct file names, ...
The html doesn't show up for security reasons.
But there are ways to show some tags, or even every... which isn't advisible.
This happens because of htmlentities .
If you comment that line, the html will display.
A classic example of what a user could do is writing (in this case, not harmful but boring):
Commenting the code did the trick! I've now stuck everything together in one folder so that the flash app and the php page read the same textfile and they can be edited from the php page. WooHoo!!!!!!! Break out the champagne!
With your example 1, I am able to get it to read the textfile, and display the submit button, but not write to the file. When I release the submit button, I get the error message: "Cannot open file", which is on your writetofile.php page. Everything's in the same folder. The permissions are read and write (666) across the board for the text file, test.txt.
If I need to use this script in the future, and the files aren't in the same folder, where it says $filename = 'test.txt'; should I put in the whole path, or would that be somewhere different?
Is $handle a variable already defined in PHP, but you're redefining it here? I'm a little confused by defining a variable with a negative statement. Is this common? I admit to being completely clueless.
Code:
if (!$handle = fopen($filename, 'w')) {
echo "&message=Cannot open file&";
exit;
}
I'm reading this as if it means: if the variable can't open the file, echo 'can't open the file'. However the structure for me is confusing. If not the variable $handle equals fopen of test.txt for writing...
Or should I read this as if it were thus: If the variable $handle is unsuccessful at opening the textfile for writing, then echo. . . 'Cannot open file'.
I'm not really understanding what $handle actually _is_. Is it the true or false return of the success of opening the file? So that !$handle = true if opening the file is unsuccessful? And you're defining $handle in the same statement?
This is so cool! It's like a giant logic puzzle. I'm really enjoying myself.
Thanks again for your help!
Lee
Here's the whole PHP:
PHP Code:
<?php
// the name of the text file
$filename = 'test.txt';
// get the variables from flash
$somecontent = $_REQUEST['somecontent'];
// If the file doesn't exist, attempt to create it
// and open it for writing
// anything already writen will be replaced
if (!$handle = fopen($filename, 'w')) {
echo "&message=Cannot open file&";
exit;
}
// Write $somecontent to the opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "&message=Cannot write to file&";
exit;
}
// close the file
fclose($handle);
// send the variable to flash
echo "&message=$somecontent&";
?>
Here's the actionscript.
Code:
//
// place the button on the stage
// hide and position it
//
//
this.attachMovie("submit", "submit_btn", 0);
submit_btn._visible = false;
submit_btn._y = 100;
submit_btn._x = 380;
//
// create the input text field
//
this.createTextField("content_txt", 1, 0, 0, 400, 80);
content_txt.border = true;
content_txt.type = "input";
content_txt.wordWrap = true;
content_txt.multiline = true;
//
// create the LoadVars Objects
//
var read_lv = new LoadVars();
var write_lv = new LoadVars();
//
// read the content of the text file
//
read_lv.onLoad = function(success)
{
if (success) {
content_txt.text = this.message;
submit_btn._visible = true;
} else {
content_txt.text = "an error occurred";
}
};
read_lv.load("http://localhost/leeSites/writetofile_examples/1/readfile.php");
// send the variable to the php script
submit_btn.onRelease = function()
{
// text to write in the text file:
write_lv.somecontent = content_txt.text;
write_lv.onLoad = function(success)
{
if (success) {
trace("text writen to the text file:\n" + this.message);
content_txt.text = this.message;
} else {
trace("an error occurred");
}
};
// GET is for testing purposes only (in the test player) - use POST instead
write_lv.sendAndLoad("http://localhost/leeSites/writetofile_examples/1/writetofile.php", write_lv, "POST");
};
"It's kind of fun to do the impossible."
- Walt Disney