移动主机后的代码错误:mysql_fetch_array()期望参数1为资源,布尔值为

时间:2013-03-08 10:08:21

标签: php html mysql boolean hosting

所以我已经搬到新主机(从免费主机)到Crazy Domains,一切似乎都很好,但有些代码似乎正在播放。

做了一些研究,它似乎是fetch数组。现在,我迷失了解决方案。

在搬到Crazydomain托管之前,整个网站都在运作。

以下是错误消息:

  

“警告:mysql_fetch_array()要求参数1为资源,第11行的/home/lgbtrada/public_html/login.php中给出布尔值”

代码:

    <?
session_start();
include("config.php");
include("clean.php");
$login = clean($_GET[login]);
if(isset($_SESSION[usr_name]) && isset($_SESSION[usr_level]) && $login!=logout)
echo('<meta http-equiv="refresh" content="0;url=main.php" />');
else {
$ip = $_SERVER['REMOTE_ADDR'];
$sqlcontent = mysql_query("select * from usr_config");
$content = mysql_fetch_array($sqlcontent);

?>
<!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>
<link rel="stylesheet" href="css.css" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Usersystem &bull; <? echo("$content[site]");?></title>
</head>

<body>
<div align="center">
  <p>&nbsp;</p>
  <table width="50%" border="1">
    <tr>
      <td><div align="center"><? echo("$content[site]");?> UserSystem </div></td>
    </tr>
    <tr>
      <td>
      <? if($login!=login){ ?>
      <div align="center"><form method="post" action="admin.php?login=login">
        Your Username:<br />
              <input type="text" name="username" />
              <br />
          <br />
          Password:<br />
          <input type="password" name="password" />
          <br />
          <br />
          <input type="hidden" name="ip" value="<? echo("$ip");?>" />
          <input type="submit" value="Login" />
    <? if($content[pwd]==1){ ?><br /><a href="lostpw.php">Forgot Password?</a> <? } ?><br />
    <a href="register.php">Register</a></form></div>
      <? } 
      elseif($login==login)
      {
      $username = clean($_POST[username]);
      $password = md5($_POST[password]);
      $date = date("Y-m-d");
      $time = date("H:i:s");
      $sql = mysql_query("select * from usr_users where username = '$username' AND password = '$password'");
      $check = mysql_num_rows($sql);
      if($check!=1)
      {
      echo("Invalid Username or Password!");
      echo('<meta http-equiv="refresh" content="1;url=admin.php" />');
      $success = "Failed";
      if($content[loginlog]==1)
      $sqllog = mysql_query("insert into usr_logs(user, ip, time, date, success) values('$username', '$ip', '$time', '$date', '$success')");
      }
      else
      {
      $user = mysql_fetch_array($sql);
      $_SESSION[usr_name] = $user[username];
      $_SESSION[usr_level] = $user[level];
      $_SESSION[usr_ip] = $ip;
      $success = "Success";
      echo("Logged in as $username, Now redirecting..");
      echo('<meta http-equiv="refresh" content="1;url=main.php" />');
      if($content[loginlog]==1)
        $sqllog = mysql_query("insert into usr_logs(user, ip, time, date, success) values('$username', '$ip', '$time', '$date', '$success')");
      }
      }
      if($login==logout)
      {
      session_unset();
      session_destroy();
      echo("You are now logged out!");
      }
      ?></td>
    </tr>
    <tr>
      <td><? if($content[loginlog]==1){ ?>Logged: Your IP: <? echo("<b>$ip</b>");?><? } else echo("Your IP was NOT logged");?></td>
    </tr>
  </table>
  <? } ?>
</div>
</body>
</html>

通过我们的新闻系统,它会返回; “'; echo stripslashes($ myrow ['title']); echo''; echo' “; echo stripslashes($ myrow ['text1']); echo'

';回声“ “; echo''; echo' '$ myrow [ “记者”。' | '$ myrow [ “DTIME”。' |评论| '$ myrow [ “意见”。'视图(S) “; } //循环结束?&gt;“

新闻显示代码:

<?php    
// load the configuration file.    
include("config.php");    
        //load all news from the database and then OREDER them by newsid    
        //you will notice that newlly added news will appeare first.    
        //also you can OREDER by (dtime) instaed of (news id)    
        $result = mysql_query("SELECT * FROM news ORDER BY newsid DESC LIMIT 7",$connect);    
        //lets make a loop and get all news from the database    
        while($myrow = mysql_fetch_assoc($result))    
             {//begin of loop    
               //now print the results:    
               echo '<h2>';    
               echo stripslashes( $myrow['title'] );    
               echo '</h2>';    
               echo '<p>';    
               echo stripslashes( $myrow['text1'] );    
               echo '</p>';    
               echo "<br />";    
               echo '<a href="https://twitter.com/share" class="twitter-share-button" ata-url="http://www.mylasuni.com/read_more.php?id='.$myrow["newsid"].'" data-text="'.$myrow["title"].'" data-via="mylasuni" data-related="mylasuni">Tweet</a>';    
               echo '<hr>
                            <span style="float:right;"><strong><a href="profile.php?user='.$myrow["reporter"].'">'.$myrow["reporter"].'</a></strong> | '.$myrow["dtime"].' | <a href="read_more.php?id='.$myrow["newsid"].'">Comment</a> | '.$myrow["views"].' view(s)</span><br><hr>';   

             }//end of loop    
?>

看看boolean参数和一些tuts,还有其他任何可以帮助你的文章吗?请帮我解决这个问题!这个网站是有充分理由的。

4 个答案:

答案 0 :(得分:0)

看起来查询返回一个空结果。检查它是否正确连接到数据库。

答案 1 :(得分:0)

您的查询( $ sqlcontent )失败(返回false ),因此无法生成有效的查询资源。 用于查看错误, 这个,

$sqlcontent = mysql_query("select * from usr_config") or die($myQuery."<br/><br/>".mysql_error());

或使用此

echo "select * from usr_config";exit;
$sqlcontent = mysql_query("select * from usr_config");

执行脚本,复制打印在浏览器上的查询并在mysql查询窗口中运行。

答案 2 :(得分:0)

为什么不能运行简单的调试,而不是使用Stack Overflow。 在执行与数据库相关的操作时检查查询或放置异常。

答案 3 :(得分:0)

免责声明:您不应该使用mysql_函数,因为因为货物原因而不推荐使用PHP 5.5.0(参见PHP docs)。

无论如何,您的查询会返回错误。确保:

  1. 您已连接到数据库
  2. SQL查询中的字段和列是正确的:
  3. $result = mysql_query('SELECT * FROM news ORDER BY newsid DESC LIMIT 7',$connect);

    if($result)
    {
        while($myrow = mysql_fetch_assoc($result)) 
        //do stuff
    }   
    else error_log(mysql_error()); //Or echo, print or whatever