Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
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
?
235 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
  • 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
Technology Partners: 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!

 

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

571 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