Created
May 11, 2012 15:24
-
-
Save h4/2660434 to your computer and use it in GitHub Desktop.
guestbook admin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html lang="en-US"> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
</head> | |
<body> | |
<?php | |
require_once('db.inc.php'); | |
mysqli_select_db($db, "guest_book"); | |
$request = "select * from book order by id desc"; | |
$result=mysqli_query($db,$request); | |
$rows = mysqli_num_rows($result); ?> | |
<form action="delete.php" method="POST"> | |
<table> | |
<tr> | |
<th>Дата</th> | |
<th>Имя</th> | |
<th>e-mail</th> | |
<th>Сообщение</th> | |
<th>ID</th> | |
<th>Action</th> | |
</tr> | |
<?php | |
while ($r = mysqli_fetch_array($result)) { | |
?> | |
<tr> | |
<td><?php echo $r["kogda"]; ?></td> | |
<td><b><?php echo $r["name"]; ?></b></td> | |
<td><?php echo $r["email"]; ?></td> | |
<td><?php echo $r["message"];?></td> | |
<td> | |
<input type="checkbox" name="post_ids[]" value="<?php echo $r["id"];?>" /> | |
</td> | |
<td> | |
<a href="update.php?post_id=<?php echo $r["id"];?>">Изменить</a> | |
</td> | |
</tr> | |
<?php } // endfor ?> | |
</table> | |
<input type="submit" value="удалить отмеченные" > | |
</form> | |
<?php mysqli_close($db); ?> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('DB_HOST', 'localhost'); | |
define('DB_USER', 'root'); | |
define('DB_PASS', 'password'); | |
$db = mysqli_connect(DB_HOST, DB_USER, DB_PASS); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE DATABASE guest_book; | |
USE guest_book; | |
CREATE TABLE book( | |
kogda DATE NOT NULL, | |
name CHAR(50) NOT NULL, | |
email CHAR(50), | |
message text NOT NULL, | |
id smallINT AUTO_INCREMENT PRIMARY KEY | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html lang="en-US"> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
</head> | |
<body> | |
<?php | |
require_once('db.inc.php'); | |
mysqli_select_db($db, "guest_book"); | |
$post_id = $_POST['post_ids']; | |
?> | |
<pre> | |
<?php print_r($post_id);?> | |
</pre> | |
<?php | |
$request = "delete from book where id='$post_id'"; | |
// $result=mysqli_query($db,$request); | |
// if ($result) { | |
// echo 'Сообщение с id='.$post_id.' удаленов'; | |
// } | |
mysqli_close($db); ?> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html lang="en-US"> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
</head> | |
<body> | |
<FORM ACTION="add.php" METHOD="POST"> | |
<h3>Добавление сообщения в гостевую книгу:</h3> | |
<table> | |
<tr> | |
<td>Ваше имя:</td> | |
<td><INPUT TYPE="text" NAME="name"><td> | |
</tr> <tr> | |
<td>Ваш email:</td> | |
<td><INPUT TYPE="text" NAME="email"></td> </tr> | |
</table> | |
<p>Сообщение:<BR> | |
<TEXTAREA NAME="message" COLS=50 ROWS=10> </TEXTAREA> <p> | |
<INPUT TYPE="submit" VALUE="Отправить"> | |
</FORM> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html lang="en-US"> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
</head> | |
<body> | |
<?php | |
require_once('db.inc.php'); | |
mysqli_select_db($db, "guest_book"); | |
$request = "select * from book order by id desc"; | |
$result=mysqli_query($db,$request); | |
$rows = mysqli_num_rows($result); ?> | |
<table> | |
<tr> | |
<th>Дата</th> | |
<th>Имя</th> | |
<th>e-mail</th> | |
<th>Сообщение</th> | |
</tr> | |
<?php | |
while ($r = mysqli_fetch_array($result)) { | |
?> | |
<tr> | |
<td><?php echo $r["kogda"]; ?></td> | |
<td><b><?php echo $r["name"]; ?></b></td> | |
<td><?php echo $r["email"]; ?></td> | |
<td><?php echo $r["message"];?></td> | |
</tr> | |
<?php } // endfor ?> | |
</table> | |
<?php mysqli_close($db); ?> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html lang="en-US"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Обновление записи</title> | |
</head> | |
<body> | |
<?php | |
require_once('db.inc.php'); | |
mysqli_select_db($db, "guest_book"); | |
if (isset($_GET['post_id'])) { | |
$post_id = $_GET['post_id']; | |
if(isset($_POST['update'])) { | |
$name = $_POST['name']; | |
$email = $_POST['email']; | |
$message = $_POST['message']; | |
$query = "UPDATE book SET name='$name', email='$email', message='$message' WHERE id=$post_id"; | |
echo $query; | |
$result = mysqli_query($db, $query); | |
if($result) { | |
echo "Запись обновлена"; | |
} | |
} else { | |
$query = "SELECT * FROM book WHERE id=$post_id"; | |
echo $query; | |
$result = mysqli_query($db, $query); | |
$row = mysqli_fetch_array($result); | |
?> | |
<form action="" method="POST"> | |
<h3>Изменение сообщения в гостевую книгу:</h3> | |
<table> | |
<tr> | |
<td>Ваше имя:</td> | |
<td><INPUT TYPE="text" NAME="name" value="<?php echo $row['name'] ?>"><td> | |
</tr> <tr> | |
<td>Ваш email:</td> | |
<td><INPUT TYPE="text" NAME="email" value="<?php echo $row['email'] ?>"></td> </tr> | |
</table> | |
<p>Сообщение:<BR> | |
<TEXTAREA NAME="message" COLS=50 ROWS=10><?php echo $row['message'] ?></TEXTAREA> <p> | |
<INPUT TYPE="submit" name="update" VALUE="Отправить"> | |
</form> | |
<? | |
} | |
} else { | |
echo 'Укажите идентификатор'; | |
} | |
mysqli_close($db); | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment