Jump to content

Recommended Posts

Hi guys I'm tying to update the config.inc.php with the database info from the install.php

 

Install.php

 

$string = '<?php 

        $db_host = "'. $_POST["host"]. '";

        $db_user = "'. $_POST["username"]. '";

        $db_pass = "'. $_POST["password"]. '";

        ?>';



        $fp = fopen("config.inc.php", "a");

        fwrite($fp, $string);

        fclose($fp);

 

config.inc.php

$db_host = '';
$db_user = '';
$db_pass = '';

// connect to the server
$con = mysql_connect($db_host,$db_user,$db_pass) 
    or die('Failed to connect to the server');

// connect to the database
$db = mysql_select_db('marketplace')
    or die('Failed to connect to the database');

 

can someone help me on how id do this

Link to comment
https://forums.phpfreaks.com/topic/238842-fwrite-preg_replace/
Share on other sites

Well as your title suggests you've figured out that you need to use preg_replace. Try this:

 

$contents = file_get_contents('config.inc.php');

$regex = array(
'expressions' => array(
	'/\$db_host = \'\';/',
	'/\$db_user = \'\';/',
	'/\$db_pass = \'\';/'
),
'data' => array(
	'$db_host = \'' . $_POST['host'] . '\';',
	'$db_user = \'' . $_POST['username'] . '\';',
	'$db_pass = \'' . $_POST['password'] . '\';'
)
);

$contents = preg_replace($regex['expressions'], $regex['data'], $contents);

// fwrite $contents back to config.inc.php

Link to comment
https://forums.phpfreaks.com/topic/238842-fwrite-preg_replace/#findComment-1227272
Share on other sites

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.