Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Editing Text File With A PHP Form


I am trying to do something with PHP that i am sure is pretty easy. But not sure myself how to do it.

I have a file that i want to pull into a simple HTML Form text field. From that field the person can just add in content or remove content.. Click "Update" .. And it will write the new content out.. Overwriting the old file if need be.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Editing Text Files In Form Textareas?
I want to pull text files into a form text area and then edit them. to open the file I am using:

$toEdit = fopen ("../content/concept.txt", "r+"); which does not work at all unless I change the path to c:xxxxxxxxxx but I dont want to do that. If I use the hard coded path I get permission denied, if I change the file to read only it seems ok - however, I want to load it into a form textarea? Cant work this out, then I want to save it.

Its just to update a simple text schedule. there will be no special characters that need escaping etc. This is probably a pretty basic question but I have been asked to do this ASAP and my attempts so far have just confused me!

Editing And Updating Text
I'm trying to create a text editing and updating capability to help
someone who wants to maintain content on a web page without having to
know any HTML or use a web authoring tool and FTP'ng the contents.
I've already created a screen whereby the person can create new
content with a PHP program that inserts into a MySQL table. But, I'm
having a little trouble in creating the edit/update functionality.

I created an edit screen called "teach_edit.php". Based upon some
search parameters on another HTML screen, it retrieves the appropriate
text from the database. It seems to allow on screen editing.
However, when I hit the Submit button, nothing happens. It's supposed
to call another program called "teach_update.php". Here's the code
for it.

<HTML>
<HEAD>
<TITLE>Teaching Edit Program</TITLE>
</HEAD>
<BODY>
<?php

@ $db = mysql_connect('localhost', '<db name>', '<password>');
if (!$db)
{
echo "Error: Could not connect to database. Please try again
later.";
exit;
}
mysql_select_db("<db>");

$query = "select * from albert where ".$searchtype." like
'%".$searchterm."%'";

$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
$title = $row['title'];
$teaching = $row['teaching'];
$teaching = wordwrap($teaching, 60, "
", 1);
$teachnum = $row['teachnum'];
}
if ($result)
{


Editing Multiple Text Elements
I'd like to edit multiple rows with one click by the user. Basically I'd print out <input type=text name=fieldname value=$value> for each record in the table. When the user clicks submit PHP will then loop through each row updating where necessary.

Large Gap When Editing Text From Database
My first PHP project is a very simple blog system and I have a page which lists blog entries. This page provides a link to the edit page, when clicked opens the edit page and inserts the values from the database into the from. My problem is that it puts in a large gap of two tabs and two spaces the start of the from. The challenging thing is that if I slick submit, the gap is not put into the post.

Editing And Handling Vars From Text Files
I have a config file like that

a=12
b="some other values"

I want to handle these vars for my php program and also be able to edit these vals.

Editing And Deleting Flat Text Files
I am working on a php news script that uses text files for it's DB. I have most of it done except for the ability to edit or delete the articles in the DB.

I have only been coding for about a week now so my skills are pretty limited and I have not found any tutorials that cover this issue so if anyone could be kind enough as to show me how this is done I would be most greatful....

Form To Text File
I don't know anything about PHP, ASP, CGI, all I can do is use Microsoft FrontPage to edit html. But I have been searching the internet for a script (any laguage) that can send an html form to a text file. But I need the new data to replace existing data in the text file every time I submit new information.

Is this possible in PHP or any other language? I’m hosted on a UNIX server with php installed and I have access to my cgi-bin and all I need is this little script to complete my website.

Form Post To Text File
I have a form that posts to my php file which in turn writes to a text file. The way I'm doing is probably far from efficient or the right way, but it's the first thing i've ever written and I have to get it done.
The way it writes now is it just puts all the form input next to each other in a text file. I want each field to be delimited or on new line so I can read it easily. Here's a snippet of my code:

<?php>
$filename = 'orders.txt'
$fp = fopen($filename, "a");

$string4 = $_POST["email"];
$string5 = $_POST["street1"];
$string6 = $_POST["street2"];

$write = fputs($fp, $string4);
$write = fputs($fp, $string5);
$write = fputs($fp, $string6);

fclose($fp);?>

Form Editing
I am trying to call information from a MySQL database in for form of an editable form.  I want the info to be called into a box that can by typed in and so far that works. 

What I want to do next is to be able to change what is in those boxes and click an update button which updates what was called from the database to what I typed in the box.  The code I wrote is below and almost works. I'm not sure what the problem is. Code:

Deleting A Line Of Text From A Txt File From A Form
How can i delete a line of text from a .txt file using a form?

because i have a form right now that saves information from a form to a txt file for news, now i need to know how to make it so i can delete it from a form.

also, if you know how, how do you overwrite lines of text in txt files from a form?

Form Data Inserted Into A Text File
I am wondering if it would be possible to create a form and using php have the form data inserted into a text file. The data would have to be inserted in a given way.

Posting Information From A Form To A Text File
I am trying to append the results from a form to a text file.  My code is supposed to print out the results on one page, and append the results to another page each time data is entered on the form and the submit button is hit. Unfortunately, it is only printing out the message acknowledging the submit button--no data on either form. Code:

Editing Mysql Db Using A Php Form
I am working on a Sig Request database. People submit their request using a form and it's posted into a databse and then displayed beneath the request form. This is working fine. I am having trouble however with my edit.php file.

I want to be able to load a users information, which I have done using this code below. It displays in a form. I change 1 or 2 of the fields, such as the completed field and designer field and click update but it doesn't actually update the database.

The page first lists all the requests. It lists their ID, Name and then it says "Edit this Request" which opens a page with their sig request details in. Here is my code below for the edit.php file. Code:

Editing HTML In A Form?
I want to build a very basic online text editor, to allow customers to
modify their own sites' html content using a simple form with textarea
element.

I read the HTML file like so:

<?PHP

function EditText ($filepath)
{
if (!$file = file($filepath)) return false;
foreach ($file as $line) {
$value .= $line; // contains all text in file when done
}
$html = "<html><head><title>Editor</title></head>
<body>
<form method='post' action='processtext.php'>
<textarea rows=&#3940;' cols=&#3980;' name='txt' value='$value'>
<input type='submit'>
</form>
</body>
</html>";
echo $html;
return true;
}

EditText ('/sample/index.html');
?>

The problem comes when the parsed file containing html elements itself
is echoed to the browser. In itself, PHP does what it's asked, but all
browsers I tried choke on the contents of the TEXTAREA field. Best
example may be: try parsing the file containing the script itself, it
becomes a real mess.

I tried htmlspecialchars, this did not fix it. I tried addslashes to
only escape the quotes in the parsed file, also no success.

I saw one example online where 'they' preg_replaced about every possible
(x)html and php syntax element, resulting in an immensely large and slow
script. Can't imagine that's the proper way forward.

If at all possible I'd like to stay away from Javascript. Any idea if
this is a realistic approach? Are there any useable scripts available? I
searched google a lot, but I keep ending up at sites that offer html or
php editors for local use, not in a browser.

Editing Submitted Form Using Variables
I'm working an e-mail form for my web page. I want people to be able to fill out information and when the click submit, get a page that basically says, "Here is the information, is it correct?"
Then they can click either, "Yes" (and it sumbits), or "No", and it goes to another page set up like the form filled out the first time, and grabs the variables and places them in the "values". This is the code I have so far: Code:

Displaying Data In A Editing Form
I have a form that has three checkboxes. A,B&C. Data from A & C has been entered into the database by serializing it.I now want to create a edit form where the user can view his choices ticked.

<form action="postoDb.php">
A<input type="checkbox" name="Choice[]" value="A">
B<input type="checkbox" name="Choice[]" value="B">
C<input type="checkbox" name="Choice[]" value="C">
</form>

//postodb.php
$bn = serialize($Choice);
sql ="insert into table (choice) values('$bn')";

Editing Datase Entries Via A Form
How would I go about editing a row in a database via a form? I know how to get the information in the text boxes. But what i would like to do is list all the rows in the database and then if i see that one of the rows needs editing or deleting i'll have 2 links under each entry (edit and delete)...and when i click "edit" it would open up a new page with a form with all the info in each text box so i can edit and then re-submit it...

INI File Editing...
Does anybody know how to open up an ini file and edit one section?

like find the section called [votes] and just replace the values underneath it, in that section alone?

vote.ini
[votes]
a=7
b=2
c=55
d=0

find that section, replace the values with there new numbers, without having to deal with what sections come before and after this, in the ini file?

Php.ini File Editing
I need your knowledge,

I want to add to my website php.ini file to change the settings of my
mail() function so that my function is working fine except that the
sender email is not my user but nobody@hostingprovider.com so Someone
told me that its easily edited using php.ini but he dont know how, so
I thought that you could help me in this situation.

more details about my hosting:
- Linux host
- php 4.4.6
- apache

Editing An Xml File
I have an xml file that I use to store information in. I want to be able to add info to it without deleting whats in the file.

Editing Info In A File
I am using a tab delimited file to provide information for a page to be displayed. I have used fgetcsv() to get information from the file, and it returns an array of information. I was wondering if there is a way I could change information in the file. For example lets say that $content[2] = "This" how could I change it so that, $content[2] = "That". I know how to change the variable to a different value, but I haven't figured out how to change the actual file.

Editing One Line Of A File.
MySQL ahs been giving me tremendous problems ever since I tried to switch to version 5.0.20. I thought that I might make my own SQL program, out of PHP code.

But if a user of it has a table with hundreds or more entrys, editing one line would take hours. If you can't get PHP to edit one line with a few functions, what about splitting a file into three parts and then merging them together after editing the middle part, like so: Code:

Editing A (config) File
I have a file with some configation in it... I am wondering how I
correct single values in there.

The most secure is to recreate the file, then rename it.

But is there a way to correct a line in the text file?
setting1=bla -setting1=blablabla

Needless to say, there are things in there I'd like to keep at all
times.

Editing A Line In A File
I have a php file, I need to open it, find the line that reads "$pass[0]  = "fa03eb688ad8aa1db593d33dabd89bad";" and edit the value
"fa03eb688ad8aa1db593d33dabd89bad". How can I do that, I have

   #Open the file
   $ourFileName = "access.php";
   $fh = fopen($ourFileName, 'r+') or die("Can't open file");
   fclose($fh);

Editing And Overwritting Data In .txt File
I have a page whereby a text area is shown, and the initial value of it uses php to display the contents of the .txt file so that a user to update the paragraph of text shown and click submit to overwrite the .txt file with new information. The problem is i have no idea how to code it so that i can make the .txt file be over written. Code:

Keep Text In Text Boxes After Form Is Rewritten
I'm trying to make a form that does the following:

(1) the user answers a question by typing in a text box
(2) a response is then written below the form, saying whether the answer is right or wrong and, perhaps making a comment of some kind
(3) the user's answer remains visible in the original text box

I've managed to write some code that does the first two things, but despite many attempts and much searching for code examples, I've failed to find a way of getting the answer to reappear in the text box when the page is rewritten.

This is my code:

Read And Display Japanese Text From Text File
I posted a question regarding reading japanese
text from a text file.

Well, since I solved the problem, I thought I'd post my solution for
the benefit of other people with the same problem.

The plan was to make a script to read and display japanese text. I
will use it for making a japanese proverb script and for a japanese
language study script.

Method :

I wrote a simple kanji text file (saved with UTF-8 encoding)
I wrote a simple PHP script to display the file contents (saved with
UTF-8
encoding)
I specified the content-type header for the HTML page :
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

*** All files have the same encoding. ***

UTF-8 supports japanese characters.

and it works!

this is my PHP (and HTML) script :

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>PHP : Japanese Text File Read : Exercise 1</title>
</head>
<body>

<?php

$filename="japanese.txt";
//open file
$fp = fopen($filename,'r');

//loop through each line in the file
while($line=fgets($fp))
{
//output current text file line
print $line."<br>";
}
//close file handle
fclose($fp);

?>

</body>
</html>

I know it's a very simple script, for testing purposes only. It
displays the contents of the japanese text file line by line.

The key was to save all files in the same encoding (I used UTF-8) and
to specify the encoding / charset in the HTML header (<meta
http-equiv="Content-Type" content="text/html; charset=utf-8">)

Remove Text Header In Text File
I have been having trouble removeing two header lines at the top of my txt file. You will see in my code the different things I have tried but with no luck. Below I posted my script and data. I am doing a few other things in my script as you will notice but this is the only thing I am having troble with. Code:

Populating Form Text Box.
I have a PHP form for entering data on-line into a mySQL
table..
Because of the intended search facility, I require one field in the form
to be completed with exact and precise item names and spelling.
In testing, I had achieved this with look-up tables.
Ideally I would like the selected item from one of five drop-down lists
to autopopulate the form text field when selected.
Alternatively at least the option of copy and paste.
Copy and paste - for some reason will not work.
Autofill worked fine on a test form with no database connection
and in standard HTML and javascript, however, once the PHP
is added to the page neither method works.
Could anyone please point me in the direction of how to get the
autofill to work?

Form Variables And Text Characters
Well I´m having trouble with text formatting I think.
You see I have a flash form, which sends variables
via POST to a php file that looks like this:

Pointer Of Mouse And Text Form.
Anybody know wether one can create such text-form that pointer of mouse
will be automatically set in the text field of form? It means that user
can type text immediately after page has been loaded, without putting
pointer of mouse by hand in the text field.

Form Text Field Validation
I've got a form and I'm now trying to validate the text fields in it. The field I want to validate is for someones name, so there should only contain letters. Below is the function I've written to handle this. Code:

Increment A Text Field In A Form
I am creating an intranet which shows active projects and allows people to add new projects. If users want to add a new project, they fill in a form but what I want the form to display in the ProjectNumber field (which is a var char field & not the primarykey) is the last Job Number incremented by 1.

For example if the last ProjectNumber was TS0014, then the default value in the ProjectNumber field should be TS0015 - this way users know what the next job number is.
At present, the last job number in my table is TS0014. Below is the code i'm using but for some reason in the Job Number field in the form Im getting TS001? WHY? Code:

Submit Form Via A Text Link
But I have a few input fields, but the submit button is not a button but just a text link.
How can I create the text to act as a submit type to submit the form?

Updating Text In Form Submission
I am using a text area form submission to add imformation to a html webpage, and I would like to be able to edit that text in the php form at a later date after submission.
Does anyone know how to get the origonal text back into the form text area for editting and resubmission?

Form Field Text Output
How can I get html code in an editable form field to display properly? Specifically: I have text that is echoed to a form field via <? echo $text ?>

The user can then edit that text and submit. However <BR> is showing up as a literal <BR> and should be a linefeed. Is there a way to have this display properly?

Example: LINE ONE<BR>LINE TWO
should display as
LINE ONE
LINE TWO

Note that this is only a problem in the form field. It displays properly when echoed outside of the form.

How To Get Un-escaped Text From A Form Field
I have a php script that gets the text from a form field:

<?php

include("global.inc.php");

pt_register( 'POST', 'test1');
echo $test1;

?>

The text comes back fine, just some characters (', " and ) are now escaped
(', " and ). The problem is that I need the he text to be exactly as it
was entered by the user. I could process the text myself, and replace the
escaped characters, but I'd like first to understand why this is happening
and if there is a way to disable this behavior and get the unmodified text
directly.

Add A Text Box Form To Buy Button Code:
cuttently we have this code which generates a buy button on a page. where the "product_ref" call the data.

Is there an easy way to add a text box with one of these codes so a number can be entered in to post to the cart as well so the item can be personalised? Code:

Keep This Text Area From Being Edited In This Form
I need the textarea so it can not be edited by the user..... how can I hide it and keep it so it can not be changed

<textarea name="body" id="body" cols="50" rows="15">'.$_CONFIG['MAIL_BODY'].'</textarea>

this text area has an email message for my inviter script but I dont want the user to be able to alter the body...

how can this be achieved? I manages to hide the subject by ussing type hidden

but I dont know how to do it with this text area.

Writing To Heredoc From Text Area Form
I can't seem to get heredoc to populate correctly with variables through
a form.

<textarea name="Template" rows="10" cols="80">Template Here</textarea>

Contents could be something like: I want to replace $myarray[0] and
another variable $myarray[1]

I call heredoc this way:

$hubarray = explode("
", $contents);
$template = $_POST['Template'];

foreach ($hubarray as $val) {
$hostarray = explode(",", $val);

$output = <<<EOT
$template
EOT;

I'm feeding it a file that has multiple rows separated by
as array 1
and within those rows are fields separated by "," for array 2. I'm
trying to iterate through the arrays and populate heredoc($template)
accordingly.

Text Within Textarea Shifted After Redisplay Form
After a redisplay of the form, caused by errors in other fields, the
text which is in the "Observ" textarea is shifted (some 8 places) to
the right (and this each time after a redisplay). The code used in case
of redisplay is :

<tr>
<td align="right">
Observations :
</td>
<td>
<textarea align="left" cols="50" rows="10" name="Observ">
<? echo $Observ ;?></textarea>
</td>
</tr>

Validate An Email Form Text Filed
How would i run a check in my datacheck page to see if the user entered an email address in a form text field?

if(empty($email_address) || - NOT VALID EMAIL STUFF HERE -){
   $msg[] = $error12;
}

File Upload Limit Using Php Form, Can I Use FTP Somehow From Form?
My host has a 2MB limit on file uploads and can't change it but they do not
have a limit on ftp files uploads. Is there a way to use ftp from the form
to upload a file?


Getting Form Fields To Accept Images And Formatted Text
does anyone know of any applications available (or the coding) that can be used to insert formatted text or images into form fields rather than the plain text inputs that are allowed in HTML?

Formatting The Contents Of A Text Area Form Field
On my site I get users to enter a load of information in a textarea
box, however when i save this data to my mysql DB and then retrieve it,
it comes out without all the formatting, like new paragraphs and new
lines.

Can anyone tell me how you can capture the data entered into such a
field with all the formatting the user has entered like new paragraphs
etc?

Clearing The Input Text Field After Submiting The Form To A New Page
I have a page with a form with an input text field ... and when a user types his/hers ID ... and submits the form - his/hers page opens in a NEW window .... but the value (ID) that was written in the original window remains.

I want to make sure that the form input field on the original page becomes "invisible" - by refreshing/reloading the original page or just by clearing the input form after submission.

For now I have put in a meta refresh tag in the head of the html file ... but that is not the solution ... becouse I only need a one time refresh/reload of the page ... and this is to happen right after the input text value is being submitted.

Table Based Order Form That Can Email Text Entered?
I have a custom order form that I collaborated on with a friend who knows php.

The form needs updated and the code we put together is hard for me to read and update. I think the form can be refined or rewritten in a more OOP way and hopefully as sematic as possible.

The Form is for entering ready made frames. The Choices are color and size. Here is what I need to do:

Enter Name, Email, Store Number, Comments Etc.Create a table based form where users can only enter numbers in each text field.Upon completion, agreement, and submission of the order an html email is kicked to our inbox. The table remains as it was on the website due to html and a separate print css file. Code:

Detecting URL's And Html Tags In Text, Input From Form
Is it possible to check text and set a PHP variable if someone inputs links, <h1></h1> ect. and other html tags when filling out your form mail or guestbooks?

Text Box To .txt File
does anyone know how to make a text box in php that when submitted, it writes to a .txt file?


Copyright © 2005-08 www.BigResource.com, All rights reserved