代码没有相应地响应通过浏览器传递的参数

时间:2012-08-29 15:41:24

标签: php

我将以下代码放在浏览器?phase=1&step=0&fot=false中,然后我得到一个黑页。 与PHP错误

  

未定义的变量:C:\ Program Files中的fOT   (x86)\ Zend \ Apache2 \ htdocs \ Proj11 \ 1.php第219行

这是$this->createTablePages ($fOT);行。如果我将其更改为$this->createTablePages ($this->fOT),我会收到以下错误

  

未定义的属性:C:\ Program Files中的phase2 :: $ fOT   (x86)\ Zend \ Apache2 \ htdocs \ Proj11 \ 1.php第219行

我知道__constructor中的$this->IDB3 = $this->handleDatabase()->$IDB3;是对的。我该怎么做?

class phase2 {
        function __construct () {

        $dbFile = 'dbconfig.php';
        $this->dbFile = $dbFile;
        include_once ("$this->dbFile"); 


        $step = $_GET["step"];

        $username = $DB_USER;
        $password = $DB_PASS;
        $server = $DB_SERVER;
        $dbName = $DB_NAME;

        $this->step = $step;
        $this->dbFile = $dbFile;
        $this->username = $username;
        $this->password = $password;
        $this->server = $server;
        $this->dbName = $dbName;

        $db = new PDO ('mysql:host=' .$server.';dbname='.$this->dbName,$this->username,$this->password);

        $this->db = $db;

        if (empty ($_GET['fot']) ) { 
        $fOT = 'false'; 
        } elseif ($_GET['true']) { $fOT = 'true'; }

        $this->IDB = $this->handleDatabase()->$IDB;
        $this->IDB2 = $this->handleDatabase()->$IDB2;
        $this->IDB3 = $this->handleDatabase()->$IDB3;
        }



public function handleDatabase (){
// Prepare SQL Statements
    $IDB = $this->db->prepare( 
         "CREATE TABLE pages (
          id int(11) NOT NULL auto_increment,
         subject_id int(11) NOT NULL,
          menu_name varchar(30) NOT NULL,
          position int(3) NOT NULL,
          visible tinyint(1) NOT NULL,
          content text NOT NULL,
          PRIMARY KEY  (id)
    )ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=utf8");

    $IDB2 = $this->db->prepare("
        CREATE TABLE subjects (
          id int(11) NOT NULL auto_increment,
          menu_name varchar(30) NOT NULL,
          position int(3) NOT NULL,
          visible tinyint(1) NOT NULL,
          PRIMARY KEY  (id)
    )ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8");

    $IDB3 = $this->db->prepare("
        CREATE TABLE users (
          id int(11) NOT NULL auto_increment,
          username varchar(50) NOT NULL,
          hashed_password varchar(40) NOT NULL,
          PRIMARY KEY  (id)
    )ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8");
}
//Set Option to True or False

function createTablePages ($fOT){

    $r1 = $this->db->query('SHOW TABLES LIKE \'page\'');
    if (count($r1->fetchAll()) > 0 && $fOT === 'false') {
        echo "The table PAGE exists";

    } elseif ($fOT === 'true') {
        $this->IDB->execute;
                $this->stepFunction (1,false);
    }
}
function createTableSubjects ($fOT){

    $r2 = $this->db->query('SHOW TABLES LIKE \'subjects\'');
    if (count($r2->fetchAll()) > 0  && $fOT === 'false') {
        echo "The table SUBJECTS exists ";

    } elseif ($fOT === 'true') {

        $this->IDB2->execute;
        $this->stepFunction (2,false);

    }
}

function createTableUsers ($fOT){

    $r3 = $this->db->query('SHOW TABLES LIKE \'users\'');   
    if (count($r3->fetchAll()) > 0  && $fOT === 'false') {
        echo "The table USERS exists";
    } elseif ($fOT === 'true') {
        $this->IDB3->execute;
        echo "Would you like to populate all the tables?";
    }   
}


public function stepFunction ($step, $fOT){

switch ($step) {
    case 0: 
            $this->createTablePages ($fOT);
            break;
    case 1: 
            $this->createTableSubjects($fOT);
            break;
    case 2: $this->createTableUsers ($fOT);
            break;
    }


}

    }

2 个答案:

答案 0 :(得分:0)

} elseif ($fOT = 'true') {

=作业。您需要比较运算符 ==

答案 1 :(得分:0)

if (count($r1->fetchAll()) > 0 && $fOT = 'false') {

你在赋值运算符和比较运算符之间感到困惑。您需要将其更改为:

if (count($r1->fetchAll()) > 0 && $fOT === 'false') {

赋值操作返回指定的值,因此它可能不会给你你期望的结果,也会弄乱其余的逻辑。