我正在尝试显示用户名一段时间,我也用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';
}
?>
答案 0 :(得分:2)
$link = mysql_connect($db_host,$db_username, /* PASSWORD HERE */);
您需要为mysql connection指定密码。
答案 1 :(得分: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';
}
?>
答案 2 :(得分:1)
mysql_*
功能。它们已被弃用。阅读指南 here 。您的如果语句需要其结束括号。此外,mysql_connect
的语法可能需要密码,除非您在php.ini中使用mysql.default_password
作为密码。 (默认为空)
<?php
...
if(...) { // --> needs its closing brace
$link=mysql_connect($db_host,$db_username) ; // no password?
...
...
while(...) {
...
...
} //while closes here WHERE does if close?
else
...
}
?>
答案 3 :(得分: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';
答案 4 :(得分: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';
}
?>
嵌套不合适