Warning: mysqli_query() expects parameter 1 to be mysqli, null given in

前端 未结 3 1179
醉话见心
醉话见心 2020-11-22 11:49

I am trying to build a simple custom CMS, but I\'m getting an error:

Warning: mysqli_query() expects parameter 1 to be MySQLi, null given in

3条回答
  •  深忆病人
    2020-11-22 12:17

    use global scope on your $con and put it inside your getPosts() function like so.

    function getPosts() {
    global $con;
    $query = mysqli_query($con,"SELECT * FROM Blog");
    while($row = mysqli_fetch_array($query))
        {
            echo "
    "; echo "

    " . $row['Title'] . "

    " . $row['SubHeading']; echo "
    "; } }

提交回复
热议问题