I'm trying to submit a regular form with a method, the form and the method are working as expected and the data from the form is entering the database successfully but the proccess ends up with an internal server error 500. I've checked appache error log for more information and that's the specific error :
Response header name 'Location ' contains invalid characters, aborting request
It's weird that i'm receiving this error since i'm not using any headers at all.
View :
<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;
}
Controller :
public function new($array){
try{
$this->set('topics', $array);
}catch(TypeError $e){
echo 'Error : ' . $e;
}
}
Model :
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);
}