0

我有两个文件,test.phpdb.php. test.php 文件包含如下形式:

<form method="get" action="db.php">

 <form method="get" action="db.php">

    <table>
        <tr>
            <td>
                Dbhost :-
            </td>
            <td>
                <input type="text" name="dbhost" />
            </td>
        </tr>
        <tr>
            <td>
                Dbname :-
            </td>
            <td>
                <input type="text" name="dbname" />
            </td>
        </tr>
        <tr>
            <td>
                Dbusername :-
            </td>
            <td>
                <input type="text" name="dbusername" />
            </td>
        </tr>
        <tr>
            <td>
                Password :-
            </td>
            <td>
                <input type="text" name="pwd" />
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit" name="sub" />
            </td>
        </tr>
    </table>

</form>

当我提交表单时,我想在db.php文件中获取它的值。我想要 wordpress 在其 config.php 文件中的值。

4

3 回答 3

1

根据您的 method属性(可以是GETPOST),提交的值将在您的 PHP 脚本中以超全局数组$_GET$_POST.

也就是说,例如,取名为字段的值dbhost,您可以编写db.php以下内容:

echo $_GET['dbhost'];

的(如果你有<form method="post">),

echo $_POST['dbhost'];

您还可以将接收到的值分配给如下变量:

$dbuser = $_GET['dbusername'];
$dbpassword = $_GET['pwd'];
$dbname = $_GET['dbname'];
$dbhost = $_GET['dbhost'];

然后使用$dbuser, $dbpassword, $dbname,$dbhost变量连接到数据库。

于 2012-10-16T05:20:31.610 回答
0

在 db.php 文件中,使用以下代码片段:

<?php
    if(!isset($_GET["sub"])) // check if button was not pressed on the form 
    {
        header("Location: test.php");
    }
    $host     = $_GET["dbhost"];  
    $db       = $_GET["dbname"];  
    $user     = $_GET["dbusername"];
    $password = $_GET["pwd"];

    $connection = mysql_connect($host,$user,$password); 
    if (!$connection)
    {
        die('Could not connect: ' . mysql_error());
    }
    else
    {
          mysql_select_db($db, $connection);
         // Connection established! Do your work here
    }

    mysql_close($connection);
?>
于 2012-10-16T05:28:46.720 回答
0

例如,将您的表单放在名为 form.php 的文件中。然后在块之间添加行 include('db.php'); 然后您可以访问 db.php 中的变量并获取和设置它们的值。我不得不说,你想要达到的目标并没有被清楚地理解。

于 2012-10-16T05:50:52.950 回答