Jump to content

PHP save form values


sycoj0ker

Recommended Posts

Hi, ok I made a script where you can select between, safe and dangerous, the risk of getting attacked in this game, and the selected data gets posted to a .txt file which is echoed to display all the info

 

for example, http://urbandead.org/img/help/1.jpg

ive selected all the values, pressed save and final product is this: http://urbandead.org/img/help/3.jpg and when i go to edit the risk levels again the edit page returns to http://urbandead.org/img/help/2.jpg

 

I just want to know a way where the values are not only written to the .txt but are also saved, so if I had to only change one option, I dont have to update every single one (there is 100 of them).

 

basically i load up http://urbandead.org/img/help/1.jpg, change one option and save, then load it up again and instead of seeing the Unknown value on every option I see the values that were set the last time they were saved instead of the default value on every option, everytime the page is loaded

 

http://urbandead.org/img/help/form.txt - thats the form for changing values

http://urbandead.org/img/help/code.txt - thats the source code, simple just long

 

thanks for any help

Link to comment
https://forums.phpfreaks.com/topic/188306-php-save-form-values/
Share on other sites

so is form.txt what is creating the page in image 2.jpg?

and code.txt is what is creating the page in image 3.jpg?

and 1.jpg is just 2.jpg after you have manually set every value?

 

if yes, then your problem, I think, is in the code of form.txt and probably the code that runs when you post the form in 1.jpg

where ever the code that makes 3.jpg gets its data from needs to be saved somewhere. where is the data that 3.jpg uses? (in a text file or is 3.jpg only generated after you manually input the data and press submit?)

 

Link to comment
https://forums.phpfreaks.com/topic/188306-php-save-form-values/#findComment-994092
Share on other sites

I know it needs to be saved, im just asking about the best way and how to do it, at the moment the options just default once its posted. I want them to stay on what I set them, not default, whenever I load up the page.

 

3.jpg is an echo of the .txt file everything gets written to, as you can see in the supplied code.txt

Link to comment
https://forums.phpfreaks.com/topic/188306-php-save-form-values/#findComment-994097
Share on other sites

for this much data, you would either put it in a database, or you could write a function that reads/writes the values to a file. There's a lot of options, the way I usually use (which is probably not the best) is to save it in the format:

 

variableName=value for the variable

 

to read the values, write a function that opens the file, reads each line, splits each line on the first occurence of = and then I usually put the variable name as an array key and the value as the value for that key. then you can do wht you like with the data.

 

if you used a database, you could create a table using the town name as the primary key, and have a many settings (variable values) as you like for each town, just make a field for each setting value you want. then use mysql_ functions to get/put your data.

Link to comment
https://forums.phpfreaks.com/topic/188306-php-save-form-values/#findComment-994104
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.