Фатальная ошибка: вызов функции-члена query() при null in
У меня есть ошибка говорит он
Notice: Undefined variable: mysqli in C:\xampp\htdocs\cwang\users.php on line 40 Fatal error: Call to a member function query() on null in C:\xampp\htdocs\cwang\users.php on line 40
Что я уже пробовал:
dbconnect.php
<?php $con = mysqli_connect("localhost","root","","dbmargs"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } ?>
user.php
<html> <head> <style> body { background-image: url('img/indexback.jpg'); background-attachment: fixed; background-size: 100% 100%; } </style> <title>MySQLi Read Records</title> <link rel="stylesheet" type="text/css" href="css/style.css"> </head> <body> <ul class="topnav"> <li><a href="#home">Home</a></li> </ul> <?php include 'dbconnect.php'; $query = "select * from tblregister"; $result = $mysqli->query( $query ); $num_results = $result->num_rows; echo "<div><a href='add.php'>Create New Record</a></div>"; if( $num_results > 0){ echo "<table border='1'>"; echo "<tr>"; echo "<th>Firstname</th>"; echo "<th>Lastname</th>"; echo "<th>Username</th>"; echo "<th>Action</th>"; echo "</tr>"; while( $row = $result->fetch_assoc() ){ extract($row); echo "<tr>"; echo "<td>{$firstname}</td>"; echo "<td>{$lastname}</td>"; echo "<td>{$username}</td>"; echo "<td>"; //just preparing the edit link to edit the record echo "<a href='edit.php?id={$id}'>Edit</a>"; echo " / "; echo "<a href='#' onclick='delete_user( {$id} );'>Delete</a>"; echo "</td>"; echo "</tr>"; } echo "</table>";//end table }else{ //if database table is empty echo "No records found."; } //disconnect from database $result->free(); $mysqli->close(); ?> </body> </html>