PHP 破坏了我的代码

标签 php mysql select mysqli echo

我正在尝试部署一个站点,但当 PHP/MySql 代码进入服务器时出现错误。它在开发中运行良好,但在生产中却运行不佳。

我的代码到达这里,没有任何问题:

<div class="content">
  <section class="col1">
   <h1>Read reviews or write us one</h1>
  </section>
  <section class="col2">
   <button type="button" class="read">Read Reviews</button>
    <?php include ('display.php'); ?>

然后当我检查源代码时,HTML 就停在那里。我猜测 display.php 文件中的 PHP 有问题,如下所示:

<?php
$con = mysql_connect('localhost','communi3_root',"password");
mysql_select_db('communi3_cfds','communi3@localhost',"password") or die(mysql_error());
$query = "select * from reviews";
$result = mysql_query($query)or die(mysql_error());
$row = mysql_fetch_array($result);

echo "<table class='displayReviews' border='1' style='width:100%;'>";
echo "<tr stlye='display:block;margin:0em auto;'><th>Name</th><th>Review</th><th>Date</th></tr>";

while ($row = mysql_fetch_array($result))
{
    echo "<tr><td>"; 
    echo $row['monicker'];
    echo "</td><td>";
    echo $row['review'];
    echo "</td><td>";
    echo $row['date'];
    echo "</td></tr>";
}
echo "</table>";
mysql_close();
?>

最佳答案

删除一些错误后

<?php
    $con = mysql_connect('localhost','communi3_root',"password");
    mysql_select_db('communi3_cfds',$con) or               die(mysql_error());
    $query = "select * from reviews";
    $result = mysql_query($query)or die(mysql_error());
    $row = mysql_fetch_array($result);
    echo "<table class='displayReviews' border='1' style='width:100%;'>";
    echo "<tr stlye='display:block;margin:0em auto;'><th>Name</th><th>Review</th><th>Date</th></tr>";
    while ($row = mysql_fetch_array($result))
    {
        echo "<tr><td>"; 
        echo $row['monicker'];
        echo "</td><td>";
        echo $row['review'];
        echo "</td><td>";
        echo $row['date'];
        echo "</td></tr>";
    }
    echo "</table>";
    mysql_close();
    ?>

关于PHP 破坏了我的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30159901/

相关文章:

来自数组的php for循环在3次循环后停止

php - MySQL 只有在表中没有确切的行时才插入

php - 将 SteamID 与 listid 结果中的禁令持续时间匹配

php - 没有 GROUP BY 子句时 SQL 计数返回错误

javascript - Select2 本地分页/无限滚动

php - 如何在 Yii2 中仅使用 1 个连接查询来获取多 ActiveRecord 模型?

php - Laravel,如何添加即时条件以使用查询生成器进行查询

mysql - SELECT,第二个表中的 2 个计数,第三个表中的 RIGHT JOIN

php - 将整数内爆到 mysql select 语句中(结果重复)

reactjs - 将自定义组件添加到 Material-ui Select 中