Need Help with PHP Backend

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
worm5252
Forum Newbie
Posts: 5
Joined: Mon Jan 24, 2005 12:55 pm

Need Help with PHP Backend

Post by worm5252 »

Hey guy, I know <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> all for php, but I am learning through doing. I work with Krome Studio Productions and I kinda need to get this script functioning ASAP for a new site design. If I can get this script working I can have our site done by the end of the week.

Here is what I have going on
I have a Page that we use to update all pages on the site. I want to be able to click a link to dynamically load the content of corrsponding text file into a textarea on a form. We can edit the content in the form, and submit it and it saves the changes to the correct text file. My problem is with my script all changes are hardwired to save to body.txt (home page). the page can be found at http://kromepreview.t35.com/kromehome.php.

Here is the code thus far

Code: Select all

<?php
if ((is_array($_GET)) && isset($_GET&#1111;'filename'])) &#123;
  $filename = $_GET&#1111;'filename'] . '.txt';
  $fp = fopen($filename, "r");
  $contents = fread($fp, 100000);
  fclose($fp);
&#125;

// when the form is submitted, make the edits
if ((is_array($_POST)) && isset($_POST&#1111;'body'])) &#123;
  $body = stripslashes($_POST&#1111;'body']);
  $handle = fopen('body.txt', 'w');
  fwrite($handle, $body);
  fclose($handle);
&#125;
?>
<html>
<body>
<a href="kromehome.php?filename=body">Home</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="kromehome.php?filename=download">Downloads</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<form action="kromehome.php" method="post">
<textarea name="body" cols="32" rows="8">
<?php echo $contents; ?>
</textarea><br />
<input type="submit" name="submit" value="Submit" />
<input type="reset" name="Reset" value="Reset Changes" />
</form>


</body>
</html>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

there's no need to swear :roll:

I'd suggest storing the filename in the form as a hidden element.
worm5252
Forum Newbie
Posts: 5
Joined: Mon Jan 24, 2005 12:55 pm

Post by worm5252 »

I am confused, what do you mean store the filename as a hidden element.

I do know the problem with this script is in this line:
$handle = fopen('body.txt', 'w');
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the filename is passed in via the link... originally.. you can echo that information into your form so that once posted, the script will know which filename it was loaded from.
worm5252
Forum Newbie
Posts: 5
Joined: Mon Jan 24, 2005 12:55 pm

Post by worm5252 »

Can you post up some code as an example, cus I am doing something similar to that to load the files, but when I try to do that to save the file I get errors.
Post Reply