Jump to content

Recommended Posts

Hi,

 

I need some help and some advice on how i should proceed with this.

 

Let's say i have config.php with those variables:

 

<?php

$host = "localhost";
$user = "username";
$pass = "pass";
$db = "db_name";

$allow = "no";

?>

 

I will have a form that will list each of those values in a text input. Now, is it possible to update the values with this form? If i have to set $allow = "yes", will it be possible using a form?

 

Please give some advice! I searched this forum but didn't get a clue on how to achieve this!

 

Thanks, any advice is welcome.

Have a nice Day!

This sort of thing is done all of the time but I don't think you're being too clear in what you're trying to accomplish.  You probably want to store the form values you're talking about into some session variables for you to access later (I'm assuming) so you'd want to do something like this:

 

<?
if($_POST[action] == "submit")
{
$_SESSION[field] = $_POST[field];
}
?>
<form method="POST">
<input type="hidden" name="action" value="submit">
Field: <input type="text" name="field"><br>
<input type="submit" value="Submit">
</form>

 

Then you could reference $_SESSION[field] throughout any of your pages to get the value of what was submitted via the form.

Well, but i need to write the file and update whatever value is assign to the variable

 

Not sure what you mean by write to the file as itallbroken's advice would assign the value from the form to the variable????

 

 

well the point it,

 

I have a config.php page where some variable are set for the website.

 

If one day i have to change something in this config.php page (example: change $allow = 'no' TO $allow = 'yes'), instead of doing it manually in the file, i would like to do it via a form! Hope that makes sense. lol

 

 

Ok I see where you are going with this now.

What about rewriting the file entirely each time like this

:

<?php 

if (isset($_POST["Submit"])) { 

$string = '<?php  
$dbhost = "'. $_POST["dbhost"]. '"; 
$allow= "'. $_POST["allow"]. '"; 
/// more variables etc passed from form
?>'; 

$fp = fopen("config.php", "w"); 
fwrite($fp, $string); 
fclose($fp); 

} 

?> 

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.