-2

所以我已经搬到了一个新的主机(从一个免费主机)到 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 ''.$myrow["reporter"].' | '.$myrow["dtime"].' | 评论 | '.$myrow["views"].' 视图'; }//循环结束?>”

新闻显示代码:

<?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    
?>

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

4

4 回答 4

0

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

于 2013-03-08T10:18:11.367 回答
0

免责声明:您不应该使用mysql_函数,因为出于商品原因,自 PHP 5.5.0 起已弃用它(请参阅PHP 文档)。

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

  1. 您已连接到数据库
  2. 您的 SQL 查询中的字段和列是正确的:

$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
于 2013-03-08T11:09:38.350 回答
0

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

于 2013-03-08T10:50:43.813 回答
0

您的查询($sqlcontent)失败(返回 false),因此没有产生有效的查询资源。使用来查看错误,Either This,

$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 查询窗口中运行。

于 2013-03-08T10:39:37.023 回答