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

  • Home
  • SEARCH
  • 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 8454441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:02:00+00:00 2026-06-10T12:02:00+00:00

Basically my problem is the next one… the following script connects a the DB

  • 0

Basically my problem is the next one… the following script connects a the DB and creates a file…. everything works fine.. except that when it populates the file.. it doesn’t put the variables $username, $password, $server and $dbname into the file.
the created file looks like this

<?php

    // Database Constants
    $DB_SERVER ="";
    $DB_USER ="";
    $DB_PASS ="";
    $DB_NAME ="";
    ?>

but it should have something inside the quotes :S

my script is as follows

<?php 
//DB Config File
$dbFile = 'dbconfig.php';

function createfile ($dbFile) {
        //Creates File and populates it.
        $fOpen = fopen($dbFile, 'w');

            $fString .= "<?php\n";
            $fString .= "// Database Constants\n";
            $fString .= "\$DB_SERVER =" . "\"" . $server . "\";\n";
            $fString .= "\$DB_USER =" . "\"" . $username . "\";\n";
            $fString .= "\$DB_PASS =" . "\"" . $password . "\";\n";
            $fString .= "\$DB_NAME =". "\"" . $dbname . "\";\n";
            $fString .= "?>";

        fwrite($fOpen, $fString);
        fclose($fOpen);
return true;
}


if (isset($_POST['submit'])) {

$username = $_POST['username'];
$password = $_POST['password'];
$server = $_POST['server'];
$dbname = $_POST['dbname'];


try {
$db = new PDO ('mysql:host=' .$server.';dbname='.$dbname,$username,$password);

if ($db) { //if succesful at connecting to the DB

if (file_exists($dbFile)){
    if (is_readable($dbFile) && is_writable($dbFile)){ 

        //Creates File, populates it and redirects the user

    if (createfile($dbFile)) { 
    header("Location: http://http://localhost/proj11/install2.php");
    exit ();
            }


        } else { 

        $msg = "2The file {$dbFile} cannot be accessed. Please configure the file manualy or grant Write and Read permission.";  }

    } else {

        //Creates File, populates it and redirects the user

    if (createfile($dbFile)) {

    header("Location: http://http://localhost/proj11/install2.php");
    exit ();
            }

        }


}

} catch (PDOException $e) { //Catchs error if can't connect to the db.
    $msg = 'Connection failed: ' . $e->getMessage();
}


}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>

<body>
<form id="iForm" method="post" action="install.php">
<label id="username" >Username</label>
<input id="username" name="username"/>
<label id="password">Password</label>
<input id="password" name="password" />
<label id="server" >Server</label>
<input id="server" name="server"/>
<label id="dbName" >dbName</label>
<input id="dbName" name="dbname"/>

<input type="submit" name="submit" value="submit" />
</form>
<p id="error"><?php echo $msg ?></p>
</body>
</html>
  • 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-06-10T12:02:01+00:00Added an answer on June 10, 2026 at 12:02 pm

    you need to convert :

    function createfile ($dbFile) {
            //Creates File and populates it.
    

    to this :

    function createfile ($dbFile) {
            global $username, $password, $server, $dbname; 
            //Creates File and populates it.
    

    or this :

    function createfile ($dbFile, $username, $password, $server, $dbname) {
            //Creates File and populates it.
    

    naturaly in the last case your call become :

    createfile ($dbFile, $username, $password, $server, $dbname);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I have this problem. I have an accordion that toggles one heading open
Basically my problem is that i've adapted a piece of code found here http://social.msdn.microsoft.com/Forums/en-US/vemapcontroldev/thread/62e70670-f306-4bb7-8684-549979af91c1
My problem is basically the same than this one but on windows 7: How
So basically my problem is a seemingly simple one. You can see it in
right the problem is a smallish one but hope someone can help. Basically we
That above is basically my problem. I already browsed some other questions on SO,
Basically my problem is with the page at http://wiki.diablocommunity.com/index.php?title=Tristram_Cathedral Please see the screen shots
Im stuck with this little project in C# but basically my problem is this:
Okay guys, basically the problem I'm having is this. I've been assigned to write
I'm having a problem with the SetLength command. It's basically this problem: I work

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.