Allowing html form to edit variables

Currently I am working on a page that is going to basically function as a settings page for what I am working on and I am struggling and am not fully sure if this is possible. I was able to get the page to pull up the information in the variable but I wanted to make it so if the person decides to change the information in the box it will change the information in the config.php file.
The variable is like this

$yourname = “George”;

The code I am currently using

I am using this which I am pretty sure it’s wrong since it’s not posting but

<?php if(isset($_POST['yourname '])) $yourname =$_POST['yourname ']; ?>

The post form is like this

NEVER let a user change any type of config setting!!!

You can set config settings as “options” in their user profile database data. Then when you show various pages, you can check these settings or options and show data adjusted to the settings…

Such as user-levels… You can have a field in the user database for all users and assign them a number or name of their allowed “level” of power. Since you did not give much info, let’s say you have 5 levels of users and the top #1 level would by YOU, the admin and all #2’s would be monitors or whatever and level 5 would be general users. Then in other pages, you would check the user level and adjust the display depending on the level needed…
The “form” you displayed did not show… Well, anyway, the data from their posted info would be updated into their user database info. Then, in other pages, the page’s code would check for the data and display it.

Not really sure what this question was about. But, some thoughts one the process might help…

1 Like

You would have to write to that file, either in the entirety or by removing values in specific places.

One more thing, Bell11, normally when you have a form, you also have a SUBMIT button of some sort.
You would test to see if that button is set and if it is, then you would get all of the various posted values.
Not just one at a time. More like this:

<?PHP
   if (isset($_POST["submit-button-name"]) {
      $yourname = filter_input(INPUT_POST, "yourname");
      $youremail = filter_input(INPUT_POST, "email");
      $etc = etc...
   }
?>

Just a quick example off top of my mind… To get you started…

NO!!! Don’t advocate the submit button for that!

1 Like

Mr. @ErnieAlex, You know better than that right? :grinning:

if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
//process form
}

ok sorry for the late reply, I decided to sleep in but basically what I’m seeing is this is a stupid idea and I should instead make the values in mysql

Well, I assumed MrBell is a newbie and did not want to get him into the server request code.

And, we are not sure what is your idea as you did not really post any code for us to review.
Perhaps you need to tell us what you are attempting to do and we can assist you.

Yea of course, Basically it’s a config page for the highest administrators. I have it so general names as well as all the information to connect to the database are variables and I wanted to make a page where the people with permission to access the page can then edit these variables to whatever they want.

So for example there is a variable that says the site name on the top left. I’d like to give these admins access to changing the name of the site name on this page without having to access the code. I also wanted to give them access to changing the database information on this page. But if you guys are suggesting that I don’t do this type of thing then I understand since you’re the professionals.

Well, you can give them all the power you wish them to have. If you want them to be able to change the site name, just make sure they need to log into the site before you let them change things. If one of the highest admin’s change something, that is okay because you have allowed them to. If there are 5 of them, they might change the same thing. So they need to be aware that could happen.
Otherwise, it is your site, you tell us the rules and we can help you do the code…

Sponsor our Newsletter | Privacy Policy | Terms of Service