-7

我试图在一段时间内显示用户名,并且我也在 PHP 中编写。但它显示错误。请帮我修复错误:

<?php
    include("config.php");
    if(time() <= strtotime("2012-11-10")) {
        $link=mysql_connect($db_host,$db_username) ;
        mysql_select_db($db_name,$link) ;
        $query = mysql_query("SELECT * FROM tbluser");
        while($v = mysql_fetch_array($query)) {
            $username = $v['username'];
            echo("<center><table border='1' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='343' id='AutoNumber1'>");
            echo("<tr><td><b>UserName</b></td>");
            echo("</tr>");
            echo("<tr><td>$username</td>");
            echo("</td></tr></table>");
        }
    else
        echo 'testing period dated ended';
    }
?>
4

5 回答 5

2
$link = mysql_connect($db_host,$db_username, /* PASSWORD HERE */);

您需要为mysql 连接分配密码。

于 2012-11-07T09:46:21.520 回答
1

您缺少大括号和 mysql_connect 的第三个参数:

<?php
include("config.php");
if(time() <= strtotime("2012-11-10")) {
    $link=mysql_connect($db_host,$db_username,$password) ;
    mysql_select_db($db_name,$link) ;
    $query = mysql_query("SELECT * FROM tbluser");
    while($v = mysql_fetch_array($query)) {
        $username = $v['username'];
        echo("<center><table border='1' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='343' id='AutoNumber1'>");
        echo("<tr><td><b>UserName</b></td>");
        echo("</tr>");
        echo("<tr><td>$username</td>");
        echo("</td></tr></table>");
    }
}
else{
    echo 'testing period dated ended';
}
?>
于 2012-11-07T09:47:55.870 回答
1

不要使用mysql_*函数。它们已被弃用。阅读此处的指南后,选择不同的 API 。


您的If语句需要它的右括号。此外,for 的语法mysql_connect可能需要密码,除非您mysql.default_password在 php.ini 中使用密码作为密码。(默认为空)

<?php
...
if(...) { // --> needs its closing brace
    $link=mysql_connect($db_host,$db_username) ; // no password?
    ...
    ...
    while(...) {
    ...
    ... 
    } //while closes here WHERE does if close?
else
    ...
}
?>
于 2012-11-07T09:48:00.393 回答
0
<?php
include("config.php");
if(time() <= strtotime("2012-11-10")) {
    $link=mysql_connect($db_host,$db_username,$password) ;
    mysql_select_db($db_name,$link) ;
    $query = mysql_query("SELECT * FROM tbluser");
    while($v = mysql_fetch_array($query)) {
        $username = $v['username'];
        echo("<center><table border='1' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='343' id='AutoNumber1'>");
        echo("<tr><td><b>UserName</b></td>");
        echo("</tr>");
        echo("<tr><td>$username</td>");
        echo("</td></tr></table>");
    }

}
else
    echo 'testing period dated ended';
于 2012-11-07T09:48:40.550 回答
0

首先将第三个参数传递给mysql_connect(),即密码。

第二:

<?php
include("config.php");
if(time() <= strtotime("2012-11-10")) {
$link=mysql_connect($db_host,$db_username) ;
mysql_select_db($db_name,$link) ;
$query = mysql_query("SELECT * FROM tbluser");
while($v = mysql_fetch_array($query)) {
$username = $v['username'];
echo("<center><table border='1' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='343' id='AutoNumber1'>");
echo("<tr><td><b>UserName</b></td>");
echo("</tr>");
echo("<tr><td>$username</td>");
echo("</td></tr></table>");
 }
}
else {
echo 'testing period dated ended';
}
?>

嵌套不正确

于 2012-11-07T09:48:58.583 回答