警告:mysql_fetch_assoc()期望参数1是资源,第10行/home/u550413281/public_html/set.php中给出的布尔值

时间:2016-04-05 07:52:05

标签: php mysql

 <?php
$sitename = "csgodrugs.net";
$link = mysql_connect(" mysql.hostinger.ro", "u550413281_cosmi", "***********");          //DB!!     //IP,NICK,PW!!!
$db_selected = mysql_select_db('csgon', $link);      //NAME OF DATABASE
mysql_query("SET NAMES utf8");

function fetchinfo($rowname,$tablename,$finder,$findervalue) {
    if($finder == "1") $result = mysql_query("SELECT $rowname FROM $tablename");
    else $result = mysql_query("SELECT $rowname FROM $tablename WHERE `$finder`='$findervalue'");
    $row = mysql_fetch_assoc($result);
    return $row[$rowname];
}
?>

1 个答案:

答案 0 :(得分:0)

试试这个:

function fetchinfo($rowname,$tablename,$finder,$findervalue) {
if($finder == "1") $result = mysql_query("SELECT '$rowname' FROM '$tablename'");
else $result = mysql_query("SELECT '$rowname' FROM '$tablename' WHERE '$finder'='$findervalue'");
$row = mysql_fetch_assoc($result);
return $row[$rowname];
}

在select语句中定位变量时,只需整理您应该使用的位置&#39;&#39;

您还应该使用MySQL i 函数而不是MySQL函数,因为MySQL函数在PHP 5.5中已经过折旧,并在PHP 7.0中被删除。

http://www.w3schools.com/php/php_ref_mysqli.asp