2017-02-06 76 views
-1

我有这两个错误我找不到任何办法来解决这些问题mysqli_query预计至少2个参数

警告:mysqli_query预计至少2个参数,1只给予在

错误查询:SELECT ID,TITLE, CONTENT,AUTHOR,DATE FROM NEWS ORDER BY ID DESC。

screenshoot from the error

<?php 
    include("site.inc.php"); 

     db_login(); 

    //Generate the query so we can retrieve all titles in the DB in descending ID order 


    $query = 'SELECT `id`, `title`, `content`, `author`, `date` FROM `news` ORDER BY `id` DESC'; 
    $result = mysqli_query($query) 
     or die ("Error in query: $query. " . mysqli_connect_error()); 

     // if records are present 
if (mysql_num_rows($result) > 0) { 

    while($send = mysql_fetch_object($result)) { 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>test</title> 
</head> 
<table cellpadding="0" cellspacing="0"> 
<tr> 
<td> 
<?php 
echo"$send->content"; 


?> 
</td> 
</tr> 
<tr> 
<?Php 
echo "$send->author"; 
} 
} 
?> 

</tr> 
<br> 

</table> 

功能db_login

<?php 


$confg['db_uname'] = "root";  
$confg['db_paswd'] = "";  
$confg['db_host'] = "localhost"; 
$confg['db_dbase'] = "dbname";  



function db_login() { 

global $confg; 

$link = @mysqli_connect($confg['db_host'], $confg['db_uname'], $confg['db_paswd']) or die("Error connecting: " . mysql_error()); 

@mysqli_select_db($confg['db_dbase'], $link); 
mysqli_query($link,"set names 'utf8';"); 
} 



function db_logout() { 

@mysqli_close($link); 

} 

?> 
+1

'mysqli_query($查询)'=>'mysqli_query($连接,$查询)' – Qirel

+1

正如错误状态。所以,RTM http://php.net/manual/en/mysqli.query.php - 你真的应该有谷歌的错误,并在发布之前阅读手册。 –

+0

我google'd错误,我没有找到解决方案 – Bacha

回答

0

添加链接到你的执行

$result = mysqli_query($link, $query) 
     or die ("Error in query: $query. " . mysqli_connect_error()); 
+0

当我添加链接:UNDEFINED VARIABLE链接之前发出警告 – Bacha

+0

U需要返回$链接在您的函数db_login和更改后db_login();到$ link = db_login(); –

+0

Juste认为:在db_login()的末尾添加“return $ link”并更改“db_login();”到“$ link = db_login();”在你的主文件 –

0

您需要同时使用mysqli_query()传递的连接字符串。

您的查询应该是这样的:

$query = 'SELECT `id`, `title`, `content`, `author`, `date` FROM `news` ORDER BY `id` DESC'; 
$result = mysqli_query($link, $query) or die ("Error in query: $query. " . mysqli_connect_error()); 
+0

当我添加链接:UNDEFINED VARIABLE链接之前警告 – Bacha

+0

返回函数'db_login()'的连接字符串。 –

相关问题