刚接触PHP,一些地方还不懂,请高手指教
其实是表单的问题,不能对变量赋值<html>
<head>
<title>创建数据库</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</head>

<?php
$db_host=true;
$db_user=true;
$db_pass=true;
$db_name=true;
$message="";
if(isset($_GET["$db_host"])){
    $db_host=false;
    $message.="服务器名不能为空 ";
}
if(isset($_GET["$db_user"])){
    $db_user=false;
    $message.="数据库用户名不能为空 ";
}
if(isset($_GET["$db_pass"])){
    $db_pass=false;
    $message.="用户密码不能为空 ";
}
if(isset($_GET["$db_name"])){
    $db_name=false;
    $message.="数据库名不能为空 ";
}
?>
    <body>
        <table align="center">
        <caption>创建数据库</caption>
        <form action="sql.php">
        <tr>
                <td width="106">服务器名</td><td width="209"><input type="text" size="40" name="db_host" value="<?php echo $_GET["db_host"]?>"></td>
        </tr>
        <tr>
                <td>用户</td><td><input type="text" size="40" name="db_user" value="<?php echo $_GET["db_user"]?>"></td>
        </tr>
        <tr>
                <td>用户密码</td><td><input type="text" size="40" name="db_pass" value="<?php echo $_GET["db_pass"]?>"></td>
        </tr>
        <tr>
                <td>数据库名</td><td><input type="text" size="40" name="db_name" value="<?php echo $_GET["db_name"]?>"></td>
        </tr>
        <tr>
                <td> <input type="submit" name="sub" value="创建"></td>
        </tr>
        <?php
        
    //    if(isset($_GET["sub"])){
     //       if($name && $pass && $db_name){
    ///            $link=mysql_connect($db_host,$db_user,$db_pass)or die("连接失败".mysql_error());
    //        }
     //       else echo $message;
    //        if(mysql_create_db($db_name,$link))
    //        echo "数据库创建成功";
    //        else echo "chuangjianshibai";
    //       }
        ?>
        <?php
        if(isset($_GET["sub"])){
        echo "<tr><td>";
            echo $db_host;
         echo "</td></tr>";
            }
        ?>
        </form>
        </table>
</body>
</html>
无论输入什么都输出:1

解决方案 »

  1.   

    $db_host=true;
    $db_user=true;
    $db_pass=true;
    $db_name=true;
    $message="";你这样赋值当然是1啦;$db_host='localhost';
    $db_user='root';
    .....
    这样,根据你的数据库设置赋值
      

  2.   

    改成这样:
    <html>
    <head>
    <title>创建数据库</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    </head>
    <?php
    $db_host=true;
    $db_user=true;
    $db_pass=true;
    $db_name=true;
    $message="";
    if(isset($_GET["$db_host"])){
    $db_host=false;
    $message.="服务器名不能为空 ";
    }
    if(isset($_GET["$db_user"])){
    $db_user=false;
    $message.="数据库用户名不能为空 ";
    }
    if(isset($_GET["$db_pass"])){
    $db_pass=false;
    $message.="用户密码不能为空 ";
    }
    if(isset($_GET["$db_name"])){
    $db_name=false;
    $message.="数据库名不能为空 ";
    }
    ?>
    <body>
    <form action="sql.php" method="get">
    <table align="center">
    <caption>创建数据库</caption>
    <tr>
    <td width="106">服务器名</td>
    <td width="209"><input type="text" size="40" name="db_host" value="<?php echo $_GET["db_host"];?>"></td>
    </tr>
    <tr>
    <td>用户</td>
    <td><input type="text" size="40" name="db_user" value="<?php echo $_GET["db_user"];?>"></td>
    </tr>
    <tr>
    <td>用户密码</td>
    <td><input type="text" size="40" name="db_pass" value="<?php echo $_GET["db_pass"];?>"></td>
    </tr>
    <tr>
    <td>数据库名</td>
    <td><input type="text" size="40" name="db_name" value="<?php echo $_GET["db_name"];?>"></td>
    </tr>
    <tr>
    <td><input type="submit" name="sub" value="创建"></td>
    </tr>
    <?php
    if(isset($_GET["sub"])){
    if($name && $pass && $db_name){
    $link=mysql_connect($db_host,$db_user,$db_pass)or die("连接失败".mysql_error());
    }else{
    echo $message;
    }
    if(mysql_create_db($db_name,$link)){
    echo "数据库创建成功";
    }else{
    echo "chuangjianshibai";
    }
    }
    if(isset($_GET["sub"])){
    echo "<tr><td>";
    echo $db_host;
    echo "</td></tr>";
    }
    ?>
    </table>
    </form>
    </body>
    </html>
      

  3.   

    isset检查变量是否存在,将isset全部替换成empty
      

  4.   

    isset($_GET["$db_name"])), 将$_GET里面的参数前面的$全部去掉,就OK了
      

  5.   

    $link=mysql_connect($db_host,$db_user,$db_pass)
    里面的变量都付的boolean值。哈哈。
      

  6.   

    什么错?mysql_create_db这个函数的定义文件是否有引用进来