• 0

Storing data in variables and updating it?


Question

I have a file named config.php. It contains all the settings for my site, lets say I create a form and I want to update that settings. Is it possible? Just replace the values of the variables with the new one but how?

Thanks, I'm having a headache figuring this out.

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0

<?php
$INFO['site_status'] = 1;
$INFO['host'] = "localhost";
$INFO['database'] = "blog";
$INFO['username'] = "root";
$INFO['password'] = "";
$INFO['url'] = "http://localhost/blog/";
$INFO['name'] = "Manmohanjit Singh";
$INFO['tagline'] = "Where simple things meet";
$INFO['rewrite_urls'] = 1;
$INFO['excerpts_home'] = 1;
$INFO['mini_view_cataut'] = 1;
$INFO['global_post_limit'] = 7;
$INFO['global_comment_limit'] = 7;
$INFO['posts_pagination'] = 1;
$INFO['comments_pagination'] = 1;
$INFO['post_to_twitter'] = 'yes';
$twitter_username = ':p';
$twitter_password = ':p';
[.........................]

So I need to update all of that using a HTML form, is it possible?

Link to comment
Share on other sites

  • 0

If you are really just looking for the absolute shortest possible code, then name your form elements the same as the $info array keys and run this when the form is submitted.

$INFO = array_merge($INFO, $_POST);

However, that is seriously, seriously bad practice without any sort of validation. You should be going through each value and making sure it is valid input.

At the absolute least, run this code before the merge if you are putting the information in a database.

array_walk($_POST, 'mysql_real_escape_string');

Link to comment
Share on other sites

  • 0

If you are really just looking for the absolute shortest possible code, then name your form elements the same as the $info array keys and run this when the form is submitted.

$INFO = array_merge($INFO, $_POST);

However, that is seriously, seriously bad practice without any sort of validation. You should be going through each value and making sure it is valid input.

At the absolute least, run this code before the merge if you are putting the information in a database.

array_walk($_POST, 'mysql_real_escape_string');

Thats a good trick, but couldn't I just use do some validation before that code?

if(empty($_POST['url'])) {
 $error = 'error';
}
[..............]
if(empty($error)) {
$INFO = array_merge($INFO, $_POST);
}

Link to comment
Share on other sites

  • 0
Thats a good trick, but couldn't I just use do some validation before that code?

I don't understand why that statement is posed as a question. Yes, you could and should validate the input before merging, as I said.

Link to comment
Share on other sites

  • 0

I don't understand why that statement is posed as a question. Yes, you could and should validate the input before merging, as I said.

Sorry. Didn't read you post properly :( Thanks for the help.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.