致命错误:在null中调用成员函数query() [英] Fatal error: call to a member function query() on null in
本文介绍了致命错误:在null中调用成员函数query()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个错误,它说
I have an errors it says
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
What I have tried:
dbconnect.php
<?php
$con = mysqli_connect("localhost","root","","dbmargs");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
user.php
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>
推荐答案
con = mysqli_connect(localhost,root, , dbmargs);
if(mysqli_connect_errno())
{
echo无法连接到MySQL:。 mysqli_connect_error();
}
?>
con = mysqli_connect("localhost","root","","dbmargs"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } ?>
user.php
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 ;
query = "select * from tblregister";
result =
这篇关于致命错误:在null中调用成员函数query()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文