gpt4 book ai didi

php - 网页不显示db内容

转载 作者:行者123 更新时间:2023-11-29 11:44:19 25 4
gpt4 key购买 nike

我正在尝试显示数据库中的内容。没有显示任何值。为什么我的代码不起作用?我也运行了 xampp 服务器!

<html>
<body>
<?php$username="";$password="";$database="login";
mysql_connect("localhost:170",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM logindetails";
$result=mysql_query($query);
$num=mysql_numrows($result);mysql_close();?>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<td>
<font face="Arial, Helvetica, sans-serif">Value1</font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif">Value2</font>
</td>
</tr>
<?php$i=0;while ($i < $num) {$f1=mysql_result($result,$i,"Username");
$f2=mysql_result($result,$i,"Email");?>
<tr>
<td>
<font face="Arial, Helvetica, sans-serif"><?php echo '$f1'; ?></font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"><?php echo '$f2'; ?></font>
</td>

</tr>
<?php$i++;}?>
</body>
</html>

最佳答案

您的 php 中有一个拼写错误:

$num = mysql_numrows( $result );

没有 mysql_numrows 函数,将其更改为:

$num = mysql_num_rows( $result );

另请注意:

mysql_ was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used.

(来自PHP官方网站)

关于php - 网页不显示db内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35214898/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com