Parse error - Newbie

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zepher2
Forum Newbie
Posts: 5
Joined: Tue Mar 25, 2008 7:10 pm

Parse error - Newbie

Post by zepher2 »

~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


I am trying to use a form to create a new file.
With some help I got the form and the php process to create a file in a subdirectory. Then I tried to add code to see if a file of the same name exists in the directory and avoid overwriting it.

This is the php process code:

Code: Select all

<?php 
$pagename = $_POST["pagename"]; // gets the form variable if globals are on or off 
$copyFrom = "templates/pagetemplate.php"; 
 
$pagename_2 = $pagename.".php";
$filename = '/test_content/$pagename_2;
if (file_exists($filename)) {
    echo "The file $filename exists";
} else {
 
$copyTo = "test_content/" . $pagename . ".php";
$hasItWorked = copy($copyFrom, $copyTo); 
if($hasItWorked) echo "IT HAS WORKED!"; 
if(!$hasItWorked) echo "DOH! IT HASN'T WORKED!"; 
}
?> 
<br>
<?php 
$pagename_2 = $pagename.".php";
echo  $pagename_2;
?>
 
When I run the program, I get this error:

Parse error: parse error in /home/a/a/xxxxx.org/html/test2.php on line 19

Can anyone tell me where I am going wrong?

Thanks in advance


~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Parse error - Newbie

Post by pickle »

Syntax highlighting brings things to light from time to time ;)
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply