Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6578943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:50:10+00:00 2026-05-25T15:50:10+00:00

I have an inc file that contains 4 MySQL database variables – hostname, database,

  • 0

I have an inc file that contains 4 MySQL database variables – hostname, database, username and password. These inc file is included in other php files to execute database queries.

What I would like to do is to create a form that can update this inc file so the MySQL variables can be changed. As a real novice I am not sure how to approach this, so any help is greatly appreciated.

Thank you very much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:50:11+00:00Added an answer on May 25, 2026 at 3:50 pm

    You have to be very careful doing things like this, more often than not it allows people to hack and/or break your application.

    What you need to do is simply overwrite your file with the new values – how you collect those values is up to you.

    Lets assume that you’re collecting the values through a POST form submission from a web page, you could do something like this:

    <?php
    
      // Create the new file contents
      // Be careful not to add any extra leading/trailing whitespace before or after
      // the opening and closing tags!
      $newFileContents = "<?php
    
      \$mysqlHostName = '{$_POST['newhost']}';
      \$mysqlDBName = '{$_POST['newdb']}';
      \$mysqlUserName = '{$_POST['newuser']}';
      \$mysqlPassword = '{$_POST['newpass']}';
    ";
    
      // Overwrite your file
      file_put_contents('mysqlconfig.php',$newFileContents);
    

    Hopefully that should get you started, but you will still need to do a lot of work, such as sanitizing the input, possibly testing whether the new details work before you overwrite your config file, including you config file afterwards to ensure that it works, etc etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file that contains about 100000 articles. The structure of file
I have an xml file with a node that contains some c# code. <Script
I have a config.inc file in a web application that I am building. It
I have a text file that contains an HTML code, and I want to
I have 2 files namely: uploading.php emaillinks.php both include a file inc.php which has
I have a html_headers.inc.php script that I want to include in every script on
Okay, so I'm using perl to read in a file that contains some general
I have inherited a Visual Studio project that contains hundreds of files. I would
I have created a user page with a menu that contains a logout button.
I have a comma separated CSV file contains NASDAQ symbols . I use Scanner

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.