mysqli_error()期望参数1为mysqli,给定null [英] mysqli_error() expects parameter 1 to be mysqli, null given

查看:118
本文介绍了mysqli_error()期望参数1为mysqli,给定null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种形式,可以从数据库中提取数据(具体来说是mysql),并将数据回显到<input>标记的value部分中.我已经对网站的视图部分进行了编码,以执行相同的操作,但是从数据库中的其他表执行了相同的操作,这似乎不起作用.如果将来有其他开发人员在我的网站上工作,我将使用相同的代码使更改变得容易.无论如何,它似乎没有用,但我不确定为什么.

I have a a form that pulls data from a database(mysql to be specific) and echos the data into the value section of <input> tags. It doesn't seem to be working I have coded a view section of my website to do the same thing but from a different table in my database. I use the same code to make making changes easy and if another developer works on my site in the future. Anyway it doesn't seem to be working I'm not sure why though.

我得到的完整错误:

Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /home/caseol5/public_html/jj/admin/news_update.php on line 9 

此处是错误所指的第9行:

Here is line 9 that the error is referring to:

$result = mysqli_query($link,$sql);

我知道这两个函数都不像我那样为空:

I know that both of those function are not null as I did:

echo $link
echo $sql 

在我开始感到错误之后的那一行之前,它们都不为空.

before that line after I started feting the error and they both are not null.

这是完整的代码段:

$nid = $_GET['nid'];

include ("../sql/dbConnect.php");

$sql = "SELECT * FROM jj_news WHERE news_id = $nid";
echo "<p>The SQL Command: $sql </p>";   
echo "<p>Link: $link </p>";
$result = mysqli_query($link,$sql);


if (!$result)
{
    echo "<h1>You have encountered a problem with the update.</h1>";
    die( "<h2>" . mysqli_error($link) . "</h2>") ;  
}
$row = mysqli_fetch_array($result);     
$ntitle = $row['news_title'];
$ntline = $row['news_titleline'];
$ndesc = $row['news_desc'];
$nother = $row['news_other'];

我调查了mysqli_query,找不到任何我缺少的东西.我也很疲倦地分解了代码(并运行了部分代码,并给出了相同的错误.我想这是我错过的一个小问题.我看了这个网站上的另一个问题,该问题有点类似,但没有似乎有所帮助.我已经看了一段时间了,还需要另一双眼睛.

I have looked into mysqli_query and I can't find anything I'm missing. I have also tired breaking the code down (and running parts of it and it gives the same error. My guess is it something small that I missed. I've looked at other question on this site that do that are a little similar but none seem to help. I've been looking at this for a while now and need another pair of eyes.

更新

根据要求,提供我的dbconnect.php文件的内容:

As requested the contents of my dbconnect.php file:

$hostname = "localhost";    
$username = "caseol5_jjoes";                
$database = "caseol5_jj_site";              
$password = "password1";                
$link = mysqli_connect($hostname, $username, $password, $database); 
$link = mysqli_connect($hostname,$username,$password,$database) or   die("Error " . mysqli_error($link));

if (!$link)                                     
{ 
    echo "We have a problem!";

}

推荐答案

错误消息中明确指出,mysqli_query

As clearly stated in the error message, mysqli_querydocs expects the first parameter to be a mysqli resource. In your case, this parameter is called $link but it holds a null value. A proper mysqli resource is normally obtained from connecting with the database by making use of mysqli_connectdocs

我希望../sql/dbConnect.php文件包含与数据库连接的逻辑.验证$link变量是否确实在那里初始化.如果不存在,请尝试查找mysqli_connect的出现-可能是资源设置为其他变量.

I expect the ../sql/dbConnect.php file holds the logic to connect with the database. Verify whether the $link variable is indeed initialized there. If it's not there, try to find an occurrence of mysqli_connect - maybe the resource is set to a different variable.

不知道../sql/dbConnect.php到底是什么,现在的问题是您没有有效的mysqli资源用于mysqli_query.

Without knowing what exactly is in ../sql/dbConnect.php, your problem right now is that you do not have a valid mysqli resource to use for mysqli_query.

这篇关于mysqli_error()期望参数1为mysqli,给定null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆