Поэтому я пытаюсь вставить текст в уже существующую таблицу. Если я вставлю текст в текстовое поле и нажму submit, я получу var_dump на другой странице, которая показывает информацию, которую я хочу вставить, но не отправляет ее в базу данных или что-то еще. Я надеюсь, что вы можете помочь мне с тем, что я делаю неправильно.
Это мой запрос на вставку
public function insertComment($commentaar, $idBestelling){
try{
$stmt = $this->_db->prepare('UPDATE `apotheek`.`Bestelling` SET `commentaar` = :commentaar WHERE `Bestelling`.`idBestelling` = :idBestelling;');
if($stmt->execute(array(
':commentaar' => $commentaar,
':idBestelling' => $idBestelling))){
return true;
} else {
return false;
}
} catch(PDOException $e) {
echo '<p class="bg-danger">'.$e->getMessage().'</p>';
}
}
И здесь вы можете найти код с веб-страницы.
<div class="row">
<form role="form" method="post" action="/?content=bezorgen">
<div class="col-xs-12 col-sm-12 col-md-12 loginborder">
<h2 class="loginhead">Bestelling no. <?php print($data['idBestelling']); ?> <?php ($data['isSpoed'] == '0') ? print('') : print('deze bestelling is met SPOED') ?></h2>
<hr>
<div class="row col-6 col-md-6 col-sm-12 col-xs-12">
<div class="loginhead">
<h3>Commentaar</h3>
<hr>
</div>
<div>
<textarea rows="9" cols="74" name="commentaar"><?php print($data['commentaar']); ?></textarea>
</div>
</div>
<div class="row registerbtn">
<div class="col-xs-12 col-md-12" style="text-align:right;"><input type="submit" name="submit" value="Verstuur" class="btn btn-lg" tabindex="5"></div>
</div>
</div>
</form>
И php
$data = $user->getBestellingPatient($_POST['idBestelling']);
if(isset($_POST['submit'])){
$user->insertComment($_POST['commentaar'], $_POST['idBestelling']);
};
Я думаю, что вы пытаетесь обновить комментарий, который уже существует в базе данных.
Вы должны добавить скрытое поле в форму для хранения идентификатора поста (в основном автоматически увеличенный идентификатор из БД)
Добавьте ниже элемент ниже вашего элемента textarea
<input type='hidden' name='idBestelling'<?php print($data['idBestelling']); ?>/>
Таким образом, когда вы обновляете id будет передан как часть формы, вы можете получить его usinig $ _POST
Вы должны попробовать это:
$stmt = $this->_db->query('UPDATE `apotheek`.`Bestelling` SET `commentaar` = :commentaar WHERE `Bestelling`.`idBestelling` = :idBestelling;');