dongzhizhai4070 2019-01-26 00:09 采纳率: 0%
浏览 3928

将HTML网页连接到SQL Server

我试图在网页上显示来自我的Azure SQL数据库的表。 我一直在环顾四周,似乎无法弄清楚为什么这不起作用。 这是我连接到数据库的地方:

<!DOCTYPE html>
<html>

<head>
  <link rel="stylesheet" type="text/css" href="Style.css">
</head>
<?php
$host="myname.database.windows.net";
$username="theUser";
$password="password";
$database="databaseName";
$tbl_name="tableName";

$mysql = mysql_connect($host, $username, $password)or die("cannot connect"); 
mysql_select_db($database);
$sql='SELECT * FROM $tbl_name';
$result=mysql_query($sql); 

?>

这是我创建格式化表格的地方:

<table id="MySqlTable" align="center" style="width:70%">
    <thead>
      <tr>
        <th>LiftId</th>
        <th>ItemNumber</th>
        <th>ItemRegion</th>
      </tr>
    </thead>
    <tbody>

这就是我试图用从数据库中提取信息并填充行的地方:

<? php
while($row = mysql_fetch_array($result)) { 
?>
  <tr>
    <td>
      <? php echo $row['LiftId']?>
    </td>
    <td>
      <? php echo $row['ItemNumber']?>
    </td>
    <td>
      <? php echo $row['ItemRegion']?>
    </td>
  </tr>
  <? php  
}
mysql_free_result($result);
mysql_close($mysql);
?>
    </tbody>
    </table>
    </body>

    </html>

这是我从这段代码中得到的最终产品。为什么信息没有显示在行中呢? https://i.stack.imgur.com/U5d3s.png

</div>
  • 写回答

3条回答 默认 最新

  • dongzong7467 2019-01-26 00:18
    关注

    You're going to want to turn on some debugging and consider using mysqli as mysql is deprecated. https://docs.microsoft.com/en-us/azure/mysql/connect-php here's a good tutorial

    For debugging add

    ini_set('display_errors',1);
    error_reporting(E_ALL);
    
    //and
    if (!$mysql) {
        die('Could not connect: ' . mysql_error());
    }
    

    to

    <!DOCTYPE html>
    <html>
    
    <head>
      <link rel="stylesheet" type="text/css" href="Style.css">
    </head>
    <?php
    ini_set('display_errors',1);
    error_reporting(E_ALL);
    $host="myname.database.windows.net";
    $username="theUser";
    $password="password";
    $database="databaseName";
    $tbl_name="tableName";
    
    $mysql = mysql_connect($host, $username, $password)or die("cannot connect"); 
    if (!$mysql) {
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db($database);
    $sql='SELECT * FROM $tbl_name';
    $result=mysql_query($sql); 
    
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序