douhao2026 2013-11-13 11:18
浏览 28

脚本找不到id字段值[重复]

I had two different tables for students and teachers(because both have different fields) with primary key id and all pages were opening correctly but I read that its not a good practice to have two different login forms so I created a user table with some common field for both teachers and students with primary key user_id . user_id is foreign key for both students table and teachers table. A global.inc file is included on all pages.when I provide an id in user.class.php file like $id=15; script is working properly otherwise following error is showing on all pages.Can somebody help?

   ( ! ) SCREAM: Error suppression ignored for
   ( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given 
    in C:\wamp\www\curri\web\classes\db.class.php on line 44
   Call Stack
   #    Time    Memory  Function    Location
   1    0.0008  251456  {main}( )   ..\dashboard.php:0
   2    0.0055  257088  require_once( 'C:\wamp\www\curri\web\global.inc.php' )
   ..\dashboard.php:1
   3    1.0224  378496  usertools->get( )   ..\global.inc.php:20
   4    1.0224  379224  DB->select( )   ..\usertools.class.php:56
   5    1.0229  379704  mysql_num_rows ( )  ..\db.class.php:44



   ( ! ) SCREAM: Error suppression ignored for
   ( ! ) Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given
    in C:\wamp\www\curri\web\classes\db.class.php on line 26
    Call Stack
   #    Time    Memory  Function    Location
   1    0.0008  251456  {main}( )   ..\dashboard.php:0
   2    0.0055  257088  require_once( 'C:\wamp\www\curri\web\global.inc.php' )
   ..\dashboard.php:1
   3    1.0224  378496  usertools->get( )   ..\global.inc.php:20
   4    1.0224  379224  DB->select( )   ..\usertools.class.php:56
   5    1.0232  379656  DB->processRowSet( )    ..\db.class.php:47
   6    1.0232  379912  mysql_fetch_assoc ( )   ..\db.class.php:26

These are files included on all pages.

global.inc.php----

<?php  
require_once ("classes/user.class.php");  
require_once ("classes/usertools.class.php");  
require_once ("classes/db.class.php");  

$db = new DB();  
$db->connect();  

$usertools = new usertools();  

session_start();  

if(isset($_SESSION['logged_in'])) {  
    $user = unserialize($_SESSION['user']);  
    $_SESSION['user'] = serialize($usertools->get($user->id));  
}  
?>  

usertools.class.php-----

<?php  
require_once ("user.class.php");  
require_once ("db.class.php");

class usertools {  

 public function login($username, $password, $usertype)  
 {  
  global $table;    
  $result = mysql_query("SELECT * FROM $table WHERE user_name='$username' 
      && password='$password' && user_type='$usertype'");  
    if(mysql_num_rows($result) > 0)  
    {    
    $_SESSION["user"] = serialize(new User(mysql_fetch_assoc($result)));  
            $_SESSION["login_time"] = time();  
            $_SESSION["logged_in"] = 1;  
            return true;  
        }else{  
            return false;  
        }  
    }  

    //returns a User object. Takes the users id as an input  
    public function get($id)  
    {  
        $db = new DB();  
        $result = $db->select('user', "user_id = $id");  

        return new User($result);  
    }  
} 

?>  

user.class.php---

<?php  
require_once ("db.class.php");  

class User {  
    public $id;
              .
              .
            public $usertype;

    function __construct($data) {  
          $this->id = (isset($data['id'])) ? $data['id'] : "";
        .
                    .
      $this->usertype = (isset($data['user_type'])) ? $data['user_type'] : "";
    }  

    public function saveteacher($isNewUser = false) {  

       global $table;
        $db = new DB();  

                 $data = array( 
                "user_name" => "'$this->username'",
                "email" => "'$this->email'",  
                 .
                                     .
                                     .    
                "user_type" => "'$this->usertype'" );
             $this->id = $db->insert($data, 'user');
            $data1 = array(
             "user_id" => "'$this->id'",
             "teacher_id" => "'$this->teacher_id'",
                                .
                                .                   
                             "subject" => "'$this->subject'",
              );

            $db->insert($data1, 'teachers');
        }  
        return true;  
    }  

    public function savestudent($isNewUser = false) {  

    }


}  

?>  

db.class.php---

<?php  
 class DB {  
    protected $db_host = "localhost"; 
    protected $db_user = "root";  
    protected $db_password = "";  
    protected $db_name = "db_name";
        public $table;

    public function connect() {  
    $conn= mysql_connect($this->db_host, $this->db_user, $this->db_password);  
    mysql_select_db($this->db_name);  
    return true;  
    }  

        public function processRowSet($rowSet, $singleRow=false)  
    {  
        $resultArray = array();  
        while($row = mysql_fetch_assoc($rowSet))  
        {  
          array_push($resultArray, $row);  
        }  

        if($singleRow === true)  
            return $resultArray[0];  
        return $resultArray;  
    }  

       public function select($table, $where) {  

        $sql = "SELECT * FROM $table WHERE $where";  
        $result = mysql_query($sql);  
        if(mysql_num_rows($result) == 1)  
        return $this->processRowSet($result, true);  
        return $this->processRowSet($result);  
          }  
        }       

?>  
</div>
  • 写回答

1条回答 默认 最新

  • douxia9826 2013-11-13 11:27
    关注

    It seems that you are using the scream extension.

    From the manual:

    The scream extension gives the possibility to disable the silencing error control operator so all errors are being reported. This feature is controlled by an ini setting.

    Scream is an extension for debugging that aims to display as many error messages as possible. This is done by ignoring the @ operator and always having the highest error_reporating level available. (regardless of your error_reporting setting). So you will have to deactivate the extension in your php.ini:

    scream.enabled = off
    

    BTW: I would not update a server having 170 websites with code errors. It's a ticking bomb now. It would be better to migrate them site by site to the new PHP version. Maybe having two servers parallel during the migration process.

    评论

报告相同问题?

悬赏问题

  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗