?
Solved

Have created form to text PHP script . Need help to do the opposite: script from text file to form

Posted on 2003-03-19
12
Medium Priority
?
227 Views
Last Modified: 2013-11-18
Hello,

See below PHP code. This takes data from a form and writes a text file (see sample below) massaged into correct format for flash to read.

I want to be able to achieve the opposite: Take data from text file and populate the form, so that people can update/edit - be able to see the last entry.

I dont know the code or where to start?! Appreciate some help here.

Regards,

Shakti Dave

--------------------------------
CODE
--------------------------------

<?php

$MESSAGE_FILE = "data.txt";
     
$DEFAULT_EXIT_PAGE = "done.htm";

function error($error_message) {
     echo $error_message."<BR>";
     exit;
}

function check_referer () {
     global $REFERERS, $HTTP_REFERER;
     if ($HTTP_REFERER != "")
          while (list($val, $ref) = each($REFERERS))
               if (preg_match("/^http:\/\/$ref/", $HTTP_REFERER))
                    return;
     error("Unauthorized access to: $HTTP_REFERER");
}

#check_referer();



while (list($key, $val) = each($HTTP_POST_VARS)) {
     $message .= "$key=".htmlspecialchars($val)."&";
}

$message = str_replace("\r", "", $message);
$message = str_replace("\n", "<BR>", $message);

$fp = fopen("$MESSAGE_FILE", "w"); // error("Can not write \$MESSAGE_FILE");
flock($fp, 1);
fputs($fp, $message);                                                    
flock($fp, 3);
fclose($fp);

if(! $exit_page)
     $exit_page = $DEFAULT_EXIT_PAGE;

Header("Location: ".$exit_page);

?>

----------------
sample text file
----------------

availableLinuxServers=22&availableWin2KServers=4&NewsUpdates=Heading One<BR>Content text content text content text<BR><BR>Heading Two<BR>More content text content text etc etc etc &Submit=Submit&

0
Comment
Question by:shaktidave
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
12 Comments
 
LVL 2

Expert Comment

by:ShockwaveRK
ID: 8172385
Hi,

If you could post a file you wish to confert or perhaps a few lines that would be helpfull

I can now say this.

If you have a file that you first want to read into a string use "fopen", if all your fields are on different lines use "file"

you can use "split" if you know the delimeter for the fields to put the fields in an array than loop trough them with your favo loop function (mine is "for")

used function found at:
http://www.php.net/manual/nl/function.fopen.php
http://www.php.net/manual/nl/function.file.php
http://www.php.net/manual/nl/function.split.php
http://www.php.net/manual/nl/control-structures.for.php

--
Greetz,
Robert, The Netherlands
0
 

Author Comment

by:shaktidave
ID: 8172425
Hi Robert

Just updated my question, including sample text file I wish to convert back to form data.

hope this helps.

Dave
0
 
LVL 2

Expert Comment

by:ShockwaveRK
ID: 8172460
Hi,

What is the result that u want? Which values in which variabels do u wnat as the result?

--
Greetz,
Robert, The Netherlands
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

Author Comment

by:shaktidave
ID: 8172492
Hi Robert

Just updated my question, including sample text file I wish to convert back to form data.

hope this helps.

Dave
0
 

Author Comment

by:shaktidave
ID: 8172517
Hi Robert,

The result I want is a web page with 3 form text boxes, which should display the values of the 3 variables:

availableLinuxServers
availableWin2KServers
NewsUpdates

The fourth variable, Submit can be ignored.

Guess I need code that:

1. reads the long text string and extracts the variables and respective values (the ampersand [&] character is the separator)

2. takes these variable and values and creates simple form with three text boxes (corresponding to the three variables) and displays it in web browser

I have the code as above to go back the other way, back to the text file.

Regards

Dave





0
 

Author Comment

by:shaktidave
ID: 8172556
Hi Robert,

The result I want is a web page with 3 form text boxes, which should display the values of the 3 variables:

availableLinuxServers
availableWin2KServers
NewsUpdates

The fourth variable, Submit can be ignored.

Guess I need code that:

1. reads the long text string and extracts the variables and respective values (the ampersand [&] character is the separator)

2. takes these variable and values and creates simple form with three text boxes (corresponding to the three variables) and displays it in web browser

I have the code as above to go back the other way, back to the text file.

Regards

Dave





0
 

Author Comment

by:shaktidave
ID: 8172583
Hi Robert,

The result I want is a web page with 3 form text boxes, which should display the values of the 3 variables:

availableLinuxServers
availableWin2KServers
NewsUpdates

The fourth variable, Submit can be ignored.

Guess I need code that:

1. reads the long text string and extracts the variables and respective values (the ampersand [&] character is the separator)

2. takes these variable and values and creates simple form with three text boxes (corresponding to the three variables) and displays it in web browser

I have the code as above to go back the other way, back to the text file.

Regards

Dave





0
 

Author Comment

by:shaktidave
ID: 8172588
sorry i dont mean to keep posting again - i was clicking refresh on the page and it happened without me knowing! I am a virgin experts exchange user ;-)
0
 
LVL 2

Expert Comment

by:ShockwaveRK
ID: 8172710
Hi,

I've done it, i think.

http://robert.spoortniet.nl/get_vars/get.php

source

http://robert.spoortniet.nl/get_vars/get.phps
(copy and paste it don't save the source)

For the data i just copy and paste the sample you provided in a data.txt of my one see for your self:

http://robert.spoortniet.nl/get_vars/

Hope this was what you wanted :)

--
Greetz,
Robert, The Netherlands
0
 
LVL 2

Accepted Solution

by:
ShockwaveRK earned 300 total points
ID: 8172721
O and please post when you have the code so i can delete it from my webdir and put it in my snippet dir

--
Greetz,
Robert, The Netherlands
0
 

Author Comment

by:shaktidave
ID: 8172795
Thankyou - exactly what I wanted.
I have the code now thanks.
Once again, thanks - you saved me so much time!

0
 
LVL 2

Expert Comment

by:ShockwaveRK
ID: 8172825
Your welcome...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question