Help - Search - Members - Calendar
Full Version: Help Needed: How To Update Php Values?
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
kitty_petiya
Hi

I'm php newbie. For example, I have a php file like this:

php Code:

<?
$value1="content1";
$value2="content2";
?>

Now I want to create a HTML site with 2 input forms allow me change the values (content1, content2) without edit above file manually. I can enter new data and click update button, then it will update new values of above php file.

How do I create this file? There are no SQL DB or complicated functions.

Thank you
swordz
Do you want the values to change permanently? Or only for that viewing?

If it's only for that viewing, that's easy, just create a form, and use $_POST variables. If it's more permanently it's more effort, I'd probably suggest fwrite.

swordz
NDBoost
I suggest using an array...

something along the lines of..
CODE
<?php
$value[1]=$_POST['content1'];
$value[2]=$_POST['content2'];
?>


Form
CODE
<form name="form1" method="POST" action="index.php">
<input type="hidden" name="hidden" value="hidden">
<input type="textbox" name="content1">
<input type="textbox" name="content2">
</form>


Use an if statement to check for the form being submitted..

CODE
<?php
if (isset($_POST['hidden'])){
$value[1]=$_POST['content1'];
$value[2]=$_POST['content2'];
}else{
echo '
<form name="form1" method="POST" action="index.php">
<input type="hidden" name="hidden" value="hidden">
<input type="textbox" name="content1">
<input type="textbox" name="content2">
</form>';
}
?>


However, if this is going to be a non authenticated area.. and open to anyone to submit data i would suggest using some sort of sanitization.. if you need more clarification on this i can help more.. just post back and let me know..

Please note that this will only store the form submitted data one time, once the page is reloaded.. it wont store it anymore.. Like swordz said, if this goes a long the lines of storign the data more permenantly.. look into some sort of SQL dbl, flat file to store the variable data.. Otherwise a much less permenant type could be a cookie or a session.. give us more details on what this script will be for and im sure someone can help.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.