Jump to content

Installation: Writing data to a variable, in another file


Recommended Posts

Say I have an installation file, and they type in all their database information & click submit. How would I get that information to open up a file called config.php, and write to the $db_host, $db_pass, $db_user, and $db variables only?

 

Is this possible? Thanks!

Write the information to file example below from http://www.tizag.com/phpT/filewrite.php

 

$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Bobby Bopper\n";
fwrite($fh, $stringData);
$stringData = "Tracy Tanner\n";
fwrite($fh, $stringData);
fclose($fh);

 

Write the information to file example below from http://www.tizag.com/phpT/filewrite.php

 

$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Bobby Bopper\n";
fwrite($fh, $stringData);
$stringData = "Tracy Tanner\n";
fwrite($fh, $stringData);
fclose($fh);

 

No, no, no. I know how to do that. But is it possible to write certain information to equal certain variables? I've had a member on here give me the code to do something like this, but I never bothered to learn the code and study it. So I regret that. <.<

im not sure of away to do what you are asking but I do understand what you mean you want to use a script to define the variables in the config.php page sadly i dont know how to do that but you can do this:

 

<?php


if(isset($_POST['install_config_do'])) {
$db_host = $_POST['db_host'];
$db_pass = $_POST['db_pass'];
$db_user = $_POST['db-user'];
$db = $_POST['db.php'];

$myFile = "config.php";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = '
<?php \n\n

$db_host = '.$db_host.'\n
$db_user = '.$db_user.'\n
$db_pass = '.$db_pass.'\n
$db = '.$db.'\n\n

mysql_connect("$db_host", "$db_user", "$db_pass") or die(mysql_error());
mysql_select_db("$b") or die(mysql_error());
';
fwrite($fh, $stringData);
fclose($fh);

} else {

echo "<form action='' method='post'>";
echo "<table border='0'>";
echo "<tr>";
echo "<td>DB Host:</td><td><input type='text' name='db_host'></td>";
echo "</tr><tr>";
echo "<td>DB User:</td><td><input type='text' name='db_user'></td>";
echo "</tr><tr>";
echo "<td>DB Pass:</td><td><input type='password; name='db_pass'></td>";
echo "</tr><tr>";
echo "<td>DB Name:</tr><td><input type='text' name='db'></td>";
echo "</tr><tr>";
echo "<td> </td><td><input type='submit' name='install_config_do' value='Install Config.php'></td>";

}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.