TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 11-09-2008, 06:45 PM   #1 (permalink)
The Acquainted
 
Peuplarchie's Avatar
 
Join Date: May 2008
Location: Québec
Posts: 104
Thanks: 10
Peuplarchie is on a distinguished road
Smile Edit posted form content & if isset quesion

Good day to all of you !
hope thing are well !

I have a piece of code here which does 2 things;

1. Show content of data.txt in html format on the page.
2. Load also "data.txt" in a textarea so you can edit it and save change.


PHP Code:

<?php

error_reporting
(0);

$action=$_POST['action'];
$textarea=$_POST['textarea'];

// Name of the page or text file to edit
$page="data.txt";

// Where to return
$return="user_comments.php";

// Get page
$data implode(""file($page)); 

if(
$action=="save"){
$newtext=stripslashes($textarea);
$newtext str_replace("<?"""$newtext);
$newtext str_replace("?>"""$newtext);
$newtext nl2br($newtext);
$fh fopen($page'w') or die("can't open file");
fwrite($fh$newtext);
fclose($fh); 
header ("location: user_comments.php");
}
else{
echo
"
<html>
<head><title>Simple Text Editor</title>
<style>
body,html{
margin:0px auto;
width:700px;
text-align:center;
}
#content{
margin:0px auto;
width:700px;
}
</style>
<body>
<div id='content'>
"
;
$ta=br2nl($data);





$file0 "data.txt"//Path to your *.txt file
$contents file($file0);
$string implode($contents);

echo 
$string;






echo
"
<a href='
$return'><-- Return to Page</a><br /><br />
Make Changes and click \"Save Changes\" at the very bottom ...<br />
<form action='user_comments.php' method='post'>
<input type='hidden' name='action' value='save'>
<textarea name='textarea' rows='15' cols='40'>
$ta</textarea>
<br />
<input type='submit' name='submit' value='Save Changes'>
</form>
</div>
</body>
</html>
"
;
}

function 
br2nl($str) {
return 
preg_replace('=<br */?>=i'""$str);
}

?>
HELP needed on:

- I'm know about an if isset function but I don't really know how to implement it into this code.

- I would also like to template each new addition in a table ??
EX: <table><tr><td>NEWLY ADDED TEXT</td></tr></table>

Can somebody at least guide me.
Thanks & take care!
__________________
That's why we are not alone on earth... let's build !
Peuplarchie is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 11:04 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design