Jump to content

[SOLVED] Displaying Saved Data in Input Fields


Styles2304

Recommended Posts

Ok, so with your guys help I've managed to make my form save the data to a text file in a format that flash approves of (I think lol).

 

Can someone point me to some tutorials that would help me with displaying the data saved in the text file in the input fields? I've found some but they were far to complex . . . they involved determining whether or not you wanted to save over that particular field and what not. I figure if all the data is loaded every time (and there isn't much of it) then if you change one field and just re-save the entire thing, that will work just fine.

 

To see an example of what I'm doing goto http://www.nestent.net/images/myspace/moviedata.php

 

Once you fill out a few of the forms and hit save, goto http://www.nestent.net/images/myspace/moviedata.txt

 

to see the text file that the data is saved too. I don't know (with the formatting) if it's possible to bring that data BACK into the form.

 

I'm sorry if these questions are horribly newbish I just don't yet know enough to even know the right questions to ask.

Link to comment
Share on other sites

Well, It's called Flat File Databases.

 

here is an simple example:

$file = file('db.txt');

foreach ($file as $lines) {

list($ident,$text) = explode('|',$lines);
if ($ident == $search){
$var = $text; }
}

echo '<input type="text" value="'.$var.'">'; 

Link to comment
Share on other sites

lol sorry . . . so I need to have "|" between the variables in the text file? Sorry . . . I know it's probably annoying but could you explain that bit of code assuming I know nothing? Not that bad but I mean can you like walk through each line? If it's an annoyance, don't worry about it, at least I'm pointed in the right direction.

Link to comment
Share on other sites

$file = file('db.txt');

1|Text One

2|text two

foreach ($file as $lines) { //Basically $lines == $file;
list($ident,$text) = explode('|',$lines);

Takes the text file search for the |'s

Make first string before the | a variable called $ident.

Make string after the | a valiable called $text

if ($ident == $search){ //if the $ident is $search..
$var = $text; }// Make a Variable called $var.
}

echo '<input type="text" value="'.$var.'">'; 
// Put the variable called $var in the textbox.

 

Hope that helps.

Link to comment
Share on other sites

Gosh, I feel retarded . . . but it doesn't. My text file is setup like this:

 

&hosturl=http://www.nestent.net/images/myspace/
&mtitle1=James Bond: Casino Royale&mimgurl1=http://imagecache2.allposters.com/images/PYR/CON6519DM-CR.jpg&mrate1=5&mreview1=Excellent Movie! Plenty of action but still a good story. A little faster than older James Bond movies but I recommend it!

 

There are more lines . . . each the same but each are numbered differently. So how do I make what you're telling me apply to what I have in that text file?

Link to comment
Share on other sites

Okay, well.

&hosturl=http://www.nestent.net/images/myspace/
&mtitle1=James Bond: Casino Royale&mimgurl1=http://imagecache2.allposters.com/images/PYR/CON6519DM-CR.jpg&mrate1=5&mreview1=Excellent Movie! Plenty of action but still a good story. A little faster than older James Bond movies but I recommend it!

Should look like:

hosturl=http://www.nestent.net/images/myspace/
mtitle1=James Bond: Casino Royale
mimgurl1=http://imagecache2.allposters.com/images/PYR/CON6519DM-CR.jpg
mrate1=5
mreview1=Excellent Movie! Plenty of action but still a good story. A little faster than older James Bond movies but I recommend it!

Then just change the identifier. :)

$file = file('db.txt');

foreach ($file as $lines) {
                                 //       this one '|' to '='
list($ident,$text) = explode('|',$lines);
if ($ident == $search){
$var = $text; }
}

echo '<input type="text" value="'.$var.'">'; 

Link to comment
Share on other sites

well . . . I did this:

 

<?php
$file = file('moviedata.txt');

for each ($file as $lines) 
{
  list($ident,$text) = explode('=',$lines);
  
  if ($ident == $search) {
    $var = $text;}
}
echo '<input type="text" value="'.$var.'">';
?>

 

But when I run the page I get this error:

 

"Parse error: syntax error, unexpected T_STRING, expecting '(' in /home/le3bl/public_html/images/myspace/moviedata.php on line 23"

 

Line 23 is "for each ($file as $lines)"

Link to comment
Share on other sites

<?php
$file = file('moviedata.txt');

for ($i=0; $i < count($file); $i++) 
{
  list($ident,$text) = explode('=',$file[$i]);
  
  if ($ident == $search) {
    $var = $text;}
}
echo '<input type="text" value="'.$var.'">';
?>
[/code[

Link to comment
Share on other sites

Ok well thanks, that fixed the error message. However, it still doesn't do what it's supposed to (unless I have it setup wrong.) It just has a random input box at the top of the form that does nothing and none of the other box show the variables they're supposed to.

 

http://www.nestent.net/images/myspace/moviedata.php

 

Check it out. The data is stored ../myspace/moviedata.txt Anyone have any ideas?

Link to comment
Share on other sites

Ok . . . the way you guys listed may have worked but I didn't understand it so I did it my own my. I ended up making an array from the save.php info, serializing, and saving it. Then, just calling it up, unserializing it and accessing the variables that way. So there you have it. Thanks for all the help though.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.