【问题标题】:What can cause internal server error 500 on form submission? [duplicate]什么会导致提交表单时出现内部服务器错误 500? [复制]
【发布时间】:2020-04-29 17:20:54
【问题描述】:

我正在尝试使用方法提交常规表单,表单和方法按预期工作,表单中的数据成功进入数据库,但过程最终出现内部服务器错误 500。 我已经检查了 appache 错误日志以获取更多信息,这就是具体错误:

响应标头名称“位置”包含无效字符,正在中止 请求

我收到这个错误很奇怪,因为我根本没有使用任何标题。

查看:

  <form action="" method="post" class="defaultForm newTopicForm" enctype="multipart/form-data">
    <?php
      if(!empty($_POST)){
        foreach($topicForm->errors() as $key => $error){
          echo '<div class="formError"><div class="error">'.$error.'</div></div>';
        }
      }
    ?>
    <div class="input"><i class="fas fa-fw fa-upload"></i><input type="file" name="image"></div>
    <div class="input"><i class="fas fa-fw fa-heading"></i><input type="text" name="title" placeholder="title" /></div>
    <textarea name="content" placeholder="content"></textarea>
    <button type="submit">submit</button>
  </form>

  if($topicForm->correct){
  try{
    $topic = new Topic();
    $topic->new(array(
      'author' => Session::get('id'),
      'title' => $_POST['title'],
      'content' => $_POST['content'],
      'date' => date('Y-m-d H:i:s'),
      'image' => $_FILES['image']
    ));
  }catch(TypeError $e){
    echo 'Error : ' . $e;
  }

控制器:

public function new($array){
  try{
    $this->set('topics', $array);
  }catch(TypeError $e){
    echo 'Error : ' . $e;
  }
}

型号:

protected function set($table, $array){
  $columns = implode(', ', array_keys($array));
  $columnsscnd = ':'.implode(', :', array_keys($array));

  $sql = "INSERT INTO $table ($columns) VALUES ($columnsscnd)";
  $stmt = $this->connect()->prepare($sql);
  $stmt->execute($array);
}

【问题讨论】:

  • &lt;/form&gt; if($topicForm-&gt;correct){
  • 粘贴错误。 @FunkFortyNiner

标签: php apache oop pdo


【解决方案1】:

您不能调用函数new,因为这是保留关键字。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-31
    • 1970-01-01
    • 1970-01-01
    • 2016-09-03
    • 2013-08-11
    • 2012-03-29
    相关资源
    最近更新 更多