【问题标题】:Works on WAMP but not on remote server适用于 WAMP 但不适用于远程服务器
【发布时间】:2014-12-10 09:56:27
【问题描述】:

我的机器上正在运行 WAMP(PHP 版本 5.5.12)。我的程序在 WAMP 上运行,但是当我在远程服务器(PHP 版本 5.4.32)上运行程序时出现以下错误:

数组([0] => 42S22 [1] => 1054 [2] => 未知列“地址”在 '字段列表')

我正在尝试将详细信息从表单传输到数据库。我不知道问题是否与表单上的以下输入有关:

Address:<br> <textarea name="address" rows="3" cols="25" WRAP="hard"><?php echo escape(Input::get('address')); ?> </textarea>

Input::get($item) 如果已设置,则返回 $_POST[$item]。其他条目如下:

Last name: <input type="text" name="last_name" value="<?php echo escape(Input::get('last_name')); ?>">

并且不要制造问题。我试过使用 print_r($e->errorInfo());在我的 catch 语句中:

catch(异常 $e) { 死($e->getMessage()); }

但这不起作用。我不知道我是否正确使用它。有人可以提供一个建议。我将不胜感激。

【问题讨论】:

    标签: php mysql


    【解决方案1】:

    我想你还没有更新你的数据库。您尝试从数据库中获取不存在的列。

    因此,请检查您在哪里有一个名为 address 的字段,并检查该字段是否正确。

    【讨论】:

      【解决方案2】:

      非常感谢您的回复。

      我认为您尚未更新数据库。您尝试获取列 来自您不存在的数据库。

      我已经检查过了,这不是问题所在。我认为问题在于以下功能:

      public function insert($table, $fields = array())
         { if(count($fields)) //true if $fields holds data
           { $keys = array_keys($fields);
      
             $values = '';  //to put inside query
      
             $x = 1;
      
            foreach($fields as $field)
            { $values .= '?';
              if($x < count($fields))
              { $values .= ', ';
              }
              $x++;
            }
         $sql = "INSERT INTO {$table} (`".implode('`, `', $keys) . "`) VALUES({$values})";
            if(!$this->query($sql, $fields)->error())
            { return true;
            }
           }
           return false;
         }
      
        public function query($sql, $darams = array())
        { 
          $this->_error = false;   //reset error
          if($this->_query = $this->_pdo->prepare($sql))
          { $x = 1;
            if(count($darams))
            { foreach($darams as $param)
              { $this->_query->bindValue($x, $param);
                $x++;
              }
            }
            if($this->_query->execute())
            { $this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ);
              $this->_count = $this->_query->rowCount();
            }
            else      //an error has occured in SQL query
            { $this->_error = true;
            }
          }
          return $this;
        }
      

      insert() 通过,$values .= '?';正在创造?作为字段的值。 query() 通过 bindValue() 为要插入的字段提供值。我有一个感觉地址,它允许新的行、空格和逗号,在绑定时会引起问题。我想知道您是否同意,如果同意,您有解决方案吗?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-06-14
        • 1970-01-01
        • 1970-01-01
        • 2017-07-16
        • 1970-01-01
        • 2019-10-03
        • 1970-01-01
        相关资源
        最近更新 更多