当我想将表单中的信息放入数据库中时,它根本没有反应,也没有收到任何错误。 我仅使用Controller en DAO表单创建了一个新的测试文件,并且在此文件中,它可以完美运行。 所以我认为我的代码没有错误。 有人可以帮我吗?
这是我的HTML:
<form method="post" action="index.php?page=detail">
<input type="hidden" name="action" value="insertData" />
<div>
<label for="inputKind">kind:</label>
<input type="text" id="inputKind" name="product" value="<?php
if (!empty($_POST['product'])) {
echo $_POST['product'];
}
?>" />
<label for="inputDate">date:</label>
<input type="date" id="inputDate" name="date" value="<?php
if (!empty($_POST['date'])) {
echo $_POST['date'];
}
?>" />
<label for="inputRegion">region:</label>
<input type="text" id="inputRegion" name="region" value="<?php
if (!empty($_POST['region'])) {
echo $_POST['region'];
}
?>" />
</div>
<div>
<button type="submit">Add Todo</button>
</div>
</form>
DAO:
public function insert($data) {
$sql = "INSERT INTO `complete` (`product`, `date`, `region`) VALUES (:product, :date, :region)";
$stmt = $this->pdo->prepare($sql);
$stmt->bindValue(':product', $data['product']);
$stmt->bindValue(':date', $data['date']);
$stmt->bindValue(':region', $data['region']);
if ($stmt->execute()) {
return $this->selectById($this->pdo->lastInsertId());
}
}
控制器:
public function nextform() {
if (!empty($_POST['action'])) {
if ($_POST['action'] == 'insertData') {
$data = array(
'product' => $_POST['product'],
'date' => $_POST['date'],
'region' => $_POST['region']
);
$insertCompleteResult = $this->completeDAO->insert($data);
}
}
$this->set('products',$this->productDAO->selectProductsByCategory($_GET['id']));
$this->set('holidays',$this->holidayDAO->selectHolidays());
$this->set('regions',$this->regionDAO->selectRegions());
$this->set('title', 'Welk cadeau');
$this->set('currentPage', 'nextform');
$complete = $this->completeDAO->selectAll();
$this->set('complete', $complete);
$this->set('title', 'Overview');
}