3raser Posted April 10, 2011 Share Posted April 10, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/233255-installation-writing-data-to-a-variable-in-another-file/ Share on other sites More sharing options...
php.ajax.coder Posted April 10, 2011 Share Posted April 10, 2011 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); Quote Link to comment https://forums.phpfreaks.com/topic/233255-installation-writing-data-to-a-variable-in-another-file/#findComment-1199593 Share on other sites More sharing options...
3raser Posted April 10, 2011 Author Share Posted April 10, 2011 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. <.< Quote Link to comment https://forums.phpfreaks.com/topic/233255-installation-writing-data-to-a-variable-in-another-file/#findComment-1199600 Share on other sites More sharing options...
PFMaBiSmAd Posted April 10, 2011 Share Posted April 10, 2011 You CAN write php code to a file. You would need to write the opening and closing php tags to the file so that the result was a valid .php code file that could be included by other .php files. Quote Link to comment https://forums.phpfreaks.com/topic/233255-installation-writing-data-to-a-variable-in-another-file/#findComment-1199623 Share on other sites More sharing options...
spiderwell Posted April 10, 2011 Share Posted April 10, 2011 the examplke given is doing exactly what you need to be able to write a new file, you can make it write whatever you want. including php variables etc. Quote Link to comment https://forums.phpfreaks.com/topic/233255-installation-writing-data-to-a-variable-in-another-file/#findComment-1199624 Share on other sites More sharing options...
Jnerocorp Posted April 10, 2011 Share Posted April 10, 2011 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>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/233255-installation-writing-data-to-a-variable-in-another-file/#findComment-1199659 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.