dragon8837 2016-02-05 01:36
浏览 216
已采纳

网页不显示数据库内容

Iam trying to display contents from the database. No values are getting displayed. Why does my code not work? I have xampp server running too !

<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>
  • 写回答

2条回答 默认 最新

  • dongxiong5546 2016-02-05 02:04
    关注

    I believe the 'mysql_connect' has been deprecated from PHP 5.5 and if you're running PHP 7.0 is has been removed. You will want to use MySQLi or PDO.

    I do not believe there is much difference between the two other than PDO can connect to other databases other than MySQL, whereas, MySQLi can only connect to MySQL.

    As to helping you fix your code. This should be close to what you need. I hope it helps

    <html>
    <body>
    <?php
    $username="root";
    $password="password"; // 'password' set to whatever it is on your DB
    $database="login";
    
    $dbc = @mysqli_connect("localhost:170",$username,$password)
        OR die( "Unable to select database");
    
    
    $query="SELECT * FROM logindetails";
    
    $result=mysqli_query($dbc, $query);
    
    $row= mysqli_fetch_array($result);
    
    mysqli_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 "$row['Username']"; ?></font>
    </td>
    <td>
    <font face="Arial, Helvetica, sans-serif"><?php echo "$row['Email']"; ?></font>
    </td>
    
    </tr>
    <?php
        //$i++;}
    ?>
    </body>
    </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序