Answer the question
In order to leave comments, you need to log in
Why is the entry from the guest book not being deleted on the page in the browser and in the database?
Good afternoon!
There is this code:
<?php
/* Основные настройки */
define('DB_HOST', 'localhost');
define('DB_LOGIN', 'root');
define('DB_PASSWORD', '');
define('DB_NAME', 'gbook');
$link = mysqli_connect(DB_HOST, DB_LOGIN, DB_PASSWORD, DB_NAME) or die('ERROR');
/* Основные настройки */
/* Сохранение записи в БД */
if($_SERVER['REQUEST_METHOD'] == 'POST'){ //проверка отправки формы
echo 'Форма отправлена' . '<br>';
$name = strip_tags($_POST["name"]);
$email = strip_tags($_POST["email"]);
$msg = strip_tags($_POST["msg"]);
echo '<br>';
//echo $name . ' ' . $email . ' ' . $msg;
$res = "INSERT INTO `msgs` (name, email, msg) VALUES ('$name', '$email', '$msg')";
mysqli_query($link, $res);
}
/* Сохранение записи в БД */
/* Удаление записи из БД */
if(isset($_GET['id']) == 'gbook' && $_GET['del'] == 'id'){
echo 'Удаление';
$query_del ="DELETE FROM msgs WHERE id = $id";
mysqli_query($link, $query_del);
}
/* Удаление записи из БД */
?>
<h3>Оставьте запись в нашей Гостевой книге</h3>
<form method="post" action="<?= $_SERVER['REQUEST_URI']?>">
Имя: <br /><input type="text" name="name" /><br />
Email: <br /><input type="text" name="email" /><br />
Сообщение: <br /><textarea name="msg"></textarea><br />
<br />
<input type="submit" value="Отправить!" />
</form>
<?php
/* Вывод записей из БД */
$show = "SELECT id, name, email, msg, UNIX_TIMESTAMP(datetime) as dt FROM msgs ORDER BY id DESC";
$res_show = mysqli_query($link, $show);
//$row = mysqli_fetch_all($res_show, MYSQLI_ASSOC);
$count = 0; //всего записей
while($row = mysqli_fetch_array($res_show, MYSQLI_ASSOC)){
$count++;
echo 'Идентификатор: ' . $bd_id = $row['id'] . '<br>';
echo 'Имя: ' . $bd_name = $row['name'] . '<br>';
echo 'Email: ' . $bd_email = $row['email'] . '<br>';
echo 'Сообщение: ' . $bd_msg = $row['msg'] .'<br>';
echo '<a href="' . 'http://localhost/mysite.local/index.php?id=gbook&del=' .$row['id'] . '">Удалить</a>';
echo '<br>';
echo '<hr>';
}
echo '<p>Всего записей в гостевой книге: ' . $count . '</p>' . '<br>';
mysqli_close($link);
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question