【问题标题】:Error 500 Using Mysql In Php在 PHP 中使用 Mysql 时出现错误 500
【发布时间】:2017-05-26 14:04:59
【问题描述】:

有人可以向我解释一下我的代码有什么问题吗?当我尝试访问该页面时,它只会给我一个 HTTP 错误 500。这是代码。

<?php
$conn = new mysqli("localhost","user","pass","db");
if(!empty($_GET['Info']))
{
    $Info = $_GET['Info'];
    $sql = "SELECT * FROM `Judges` WHERE `id` EQUALS $Info";
    $result = $conn->query($sql);

    if ($result->num_rows > 0) 
    {
        while($rows = $result->fetch_assoc()) 
        {
            $PictureFile = Null
            if(empty($rows["PictureFile"]))
            {
                $PictureFile = "MissingPicture.png";
            }
            else
            {
                $PictureFile = $rows["PictureFile"];
            }
            echo '<div><img src="' . $PictureFile . '" style="width=100px;height=100px;"> <p>This Is Just A Test Message!</p></div>';
        }
    } 
    else 
    {
        echo "<p style='text-align: center;'>Your Search Came Back With 0 Results :(</p>";
    }
}
$conn->close();
?>

【问题讨论】:

  • 您必须检查您的网络服务器日志。 500 错误可能是由多种原因引起的。
  • $sql = "SELECT * FROM Judges WHERE id EQUALS $Info";应该等于=?
  • 您的代码容易受到SQL injection 攻击。您应该使用mysqliPDO 准备好的语句和this post 中所述的绑定参数。
  • @AlexHowansky 非常感谢,我讨厌 sql 注入这种东西。

标签: php mysql http-error


【解决方案1】:

你忘记了 ;在这个命令行之后

$PictureFile = Null

我无法测试脚本,但它必须解决您的问题。

【讨论】:

  • 不,不要这样。这样的事情会发生。 :)
【解决方案2】:

将 EQUALS 更改为 = 并添加 ; $PictureFile = Null 之后

    <?php
$conn = new mysqli("localhost","user","pass","db");
if(!empty($_GET['Info']))
{
    $Info = $_GET['Info'];
    $sql = "SELECT * FROM `Judges` WHERE `id`= $Info";
    $result = $conn->query($sql);

    if ($result->num_rows > 0) 
    {
        while($rows = $result->fetch_assoc()) 
        {
            $PictureFile = Null;
            if(empty($rows["PictureFile"]))
            {
                $PictureFile = "MissingPicture.png";
            }
            else
            {
                $PictureFile = $rows["PictureFile"];
            }
            echo '<div><img src="' . $PictureFile . '" style="width=100px;height=100px;"> <p>This Is Just A Test Message!</p></div>';
        }
    } 
    else 
    {
        echo "<p style='text-align: center;'>Your Search Came Back With 0 Results :(</p>";
    }
}
$conn->close();
?>

【讨论】:

    【解决方案3】:

    $PictureFile = Null末尾添加;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-09
      • 2019-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多