mysql uroot CREATE DATABASE gbook quit mysql uroot gbook gbook sql USE

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
mysql –uroot
CREATE DATABASE gbook;
quit
mysql –uroot gbook < с:\gbook.sql
USE gbook;
DESCRIBE msgs;
<?php
define('DB_HOST', 'localhost');
define('DB_LOGIN', 'root');
define('DB_PASSWORD', 'root');
define('DB_NAME', 'gbook');
$link = mysqli_connect(DB_HOST, DB_LOGIN, DB_PASSWORD, DB_NAME);
if(isset($_POST['name']) && isset($_POST['email']) && isset($_POST['msg'])){
$name = htmlspecialchars($_POST['name']);
$email = htmlspecialchars($_POST['email']);
$msg = htmlspecialchars($_POST['msg']);
mysqli_query($link, "INSERT INTO msgs (name, email, msg) VALUES ('$name', '$email', '$msg')");
}
?>
<?php
$query = mysqli_query($link, "SELECT id, name, email, msg, UNIX_TIMESTAMP(datetime) as dt FROM msgs ORDER BY id DESC");
mysqli_close($link);
$rows = mysqli_num_rows($query);
while($row = mysqli_fetch_array($query)){
echo '<p><a href="mailto:'.$row['email'].'">'.$row['name'].'</a> '.date('d-m-Y в H:i', $row['dt']).' написал <br />'.$row['msg'].'</p>';
echo '<p align="right"><a href="http://'.$_SERVER['SERVER_NAME'].''.$_SERVER['REQUEST_URI'].'&del='.$row['id'].'">Удалить</a> </p>';
}
?>
<p>Всего записей в гостевой книге: <?= $rows; ?></p>
<?php
if(isset($_GET['del'])){
$del = htmlspecialchars($_GET['del']);
mysqli_query($link, "DELETE FROM msgs WHERE id = $del");
}
?>