RoomKid Posted February 22, 2010 Share Posted February 22, 2010 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 More sharing options...
0 Hot Posted February 22, 2010 Share Posted February 22, 2010 Generally speaking, you just have to overwrite it. $var = 'hello'; echo $var; //prints 'hello' $var = 'goodbye'; echo $var; //now prints 'goodbye' Link to comment Share on other sites More sharing options...
0 RoomKid Posted February 22, 2010 Author Share Posted February 22, 2010 That was my first idea but then again I have a long list of settings. It wouldn't be the best method. Link to comment Share on other sites More sharing options...
0 Hot Posted February 22, 2010 Share Posted February 22, 2010 If you are looking for suggestions on a specific implementation then you'll have to show us some code, mate. I thought you were just asking a general beginner question. Link to comment Share on other sites More sharing options...
0 RoomKid Posted February 22, 2010 Author Share Posted February 22, 2010 <?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 More sharing options...
0 Hot Posted February 22, 2010 Share Posted February 22, 2010 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 More sharing options...
0 RoomKid Posted February 22, 2010 Author Share Posted February 22, 2010 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 More sharing options...
0 Hot Posted February 22, 2010 Share Posted February 22, 2010 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 More sharing options...
0 RoomKid Posted February 23, 2010 Author Share Posted February 23, 2010 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 More sharing options...
0 Hot Posted February 23, 2010 Share Posted February 23, 2010 Don't frown mate, good on you for seeking a more efficient way to begin with instead of just repeating code. (Y) Repetitive code is a surefire sign of an amateur programmer. (N) Link to comment Share on other sites More sharing options...
0 Kami- Posted March 3, 2010 Share Posted March 3, 2010 Are you trying to replace them on a temporary or perm basis (as in you'll need write access to teh config.php file)? Link to comment Share on other sites More sharing options...
Question
RoomKid
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