【发布时间】: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);
}
【问题讨论】:
-
</form> if($topicForm->correct){ -
粘贴错误。 @FunkFortyNiner