如何添加MySQL数据库&用户从表单到配置文件

时间:2014-01-06 18:31:53

标签: php mysql

我在install / install.php中有这个表单:

<form method="POST" action="installing.php" onSubmit="return validatedb();" id="installform">
    <div class="form">
        <div class="initem">
            <div class="dib name">Database Host</div>
            <div class="dib value"><input type="text" name="dbhost" value="<?= $preDbHost ?>" /></div>
        </div>
        <div class="initem">
            <div class="dib name">Database Name</div>
            <div class="dib value"><input type="text" name="dbname" value="<?= $preDbName ?>" /></div>
        </div>
        <div class="initem">
            <div class="dib name">Database User</div>
            <div class="dib value"><input type="text" name="dbuser" value="<?= $preDbUser ?>" /></div>
        </div>
        <div class="initem">
            <div class="dib name">Database Pass</div>
            <div class="dib value"><input type="text" name="dbpass" value="<?= $preDbPass ?>" /></div>
        </div>
    </div>
    <div class="stepper bbr">
        <div class="fll">Step 1/2 : Database Settings</div>
        <div class="flr"><input type="submit" value="Validate & Continue" class="btl bbr"/></div>
        <div class="cls"></div>
    </div>
</form>

在inc / config.inc.php中这段代码:

<?php

    // Error Reporting
    @error_reporting(E_ALL ^ E_NOTICE);


    /// Database Settings ///
    define('DB_NAME', '');          // MySQL database name
    define('DB_USER', '');          // MySQL database user
    define('DB_PASSWORD', '');      // MySQL database password
    define('DB_HOST', 'localhost');     // MySQL database host name (in most cases, it's localhost)


    if (isset($_SESSION['userid']) && is_numeric($_SESSION['userid']))
    {
        $userid = (int)$_SESSION['userid'];
    }

    define('Jobfia_ROOT', dirname(__FILE__) . '/');
    define('Jobfia_PAGE', TRUE);

    require_once(Jobfia_ROOT."db.inc.php");
    require_once(Jobfia_ROOT."functions.inc.php");

    if (!defined('is_Setup'))
    {
        require_once(Jobfia_ROOT."siteconfig.inc.php");
    }

?>

如何在数据库设置中通过php添加inc / config.inc.php中的表单值,同时验证它们是否是实际值?

2 个答案:

答案 0 :(得分:0)

导入文件inc / config.inc.php在文件install / install.php中 比

$DB_NAME
$DB_USER
$DB_PASSWORD
$DB_HOST

可以直接访问

答案 1 :(得分:0)

你能做的是:

选项1 - 保留db.inc.php,只要保存表单,您将覆盖该db.inc.php。 并在config.inc.php中调用它,如下所示:

// Error Reporting
@error_reporting(E_ALL ^ E_NOTICE);


/// Database Settings ///
require_once('db.inc.php')



if (isset($_SESSION['userid']) && is_numeric($_SESSION['userid']))
{
    $userid = (int)$_SESSION['userid'];
}

...
...