Ricknny 2021-04-23 18:31 采纳率: 0%
浏览 78

php $conn->close()代码报错 小白一枚求解答

遇到了这样的错误:

Undefined variable: conn on line 33

Fatal error: Uncaught Error: Call to a member function close() on null

代码如下

<link rel="stylesheet" href="course.css">

<?php

$title = "College";

include('include/header.inc');

?>

<h1>College</h1>

<?php

include('include/nav.inc');

?>

<?php

if (!empty($_GET['id'])) {

    include('include/db_connect.inc');

    $name = $_GET['courseid'];

    $sql = "select * from CourseDetails where courseid = ?";

    $stmt = $conn->prepare($sql);

    $stmt->bind_param("i", $name);

    $name = $_GET['courseid'];

    $stmt->execute();

    $result = $stmt->get_result();

    if ($result->num_rows > 0) {

        while ($row = mysqli_fetch_array($result)) {

            print "<h2>{$row['coursecode']}</h2>";

            print "<h3>by {$row['name']}</h3>";

            print "<h4>{$row['subject']}</h4>";

            print "<h5>{$row['instuctors']}</h5>";

            print "<h6>{$row['weeks']}</h6>";

            print "<p>{$row['description']}</p>";

        }

    }

}

?>

<?php

$conn->close();

include('include/footer.inc');

?>

  • 写回答

6条回答 默认 最新

  • 关注

    具体报什么错误呢?把错误信息贴出来看看

    评论

报告相同问题?

悬赏问题

  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退