Книга за гости

Първо да създадем mysql таблица

gosti.php
<html>

<head>

<meta http-equiv="content-type" content="text/html; charset=windows-1251">

</head>

<body>

<?php

$conn = @mysql_connect("localhost", "root", "") or die ("Връзката с MySQL неможе да бъде осъществена.");

$select = @mysql_select_db("register", $conn) or die ("Базата данни неможе да бъде открита.");

$arg = "id int(4) auto_increment, name varchar(40), email varchar(40), komentar text, vreme timestamp, primary key(id)";

$query = "create table gosti ($arg)";

$result = @mysql_query($query);

if($result)

{

	$msg = "<h2>Книгата за гости е създадена.</h2>";

}

else

{

	$msg = "<h2>Неуспешен опит за създаването на книгата за гости";

}

echo $msg;

?>

</body>

</html>



addpost.php

<html>

<head>

<style>

html, body{color:white;}

a:link,a:visited,a:active{color:lightblue; text-decoration:none; text-align:left;}

a:hover{color:white; text-decoration:none; text-align:left;}

h2 {text-align:left; color:white;}

</style>

<meta http-equiv="content-type" content="text/html; charset=windows-1251">

</head>

<body>

<br>

<?php

$name = $_POST['name'];

$email = $_POST['email'];

$komentar = $_POST['komentar'];

$submit = $_POST['submit'];

if (!$submit)

{

	require('includes/post.inc');

}

else

	if((!$name) or (!$email) or (!$komentar))

	{

  echo "<b>Моля попълнете всички полета.</b><br><br>";

  echo "<a href="adminpanel.php" target="center"><h3>Назад</h3></a>";

  

	}

else

{

	$conn = @mysql_connect("localhost", "root", "") or die ("Връзката неуспешна.");

	$select = @mysql_select_db("register", $conn) or die ("Селектирането неуспешно.");

	if($name and $komentar)

	{

  $query = "insert into gosti(name, email, komentar) values("$name", "$email", "$komentar")";

  $result = mysql_query($query, $conn) or die ("Заявката неможе да бъде осъществена.");

	}

	if($query)

	{

  echo "<h3>Съобщението е изпратено успешно.</h3><br><br>";

	}

}

?>

</body>

</html>


review.php

<html>

<head>

<style>

html, body{color:white;}

table{border:1px lightblue;}

th{background-color:lightgray; color:black}

td{background-color:darkgray}

.td{background-color:gray}

h2 {text-align:left; color:white;}

</style>

<meta http-equiv="content-type" content="text/html; charset=windows-1251">

</head>

<body>

<h2>Новини</h2>

<hr>

<br>

<?php

$conn = @mysql_connect("localhost", "root" , "") or die ("Грешка");

$select = @mysql_select_db("register", $conn) or die ("Грешка");

$query = "select * from gosti order by vreme desc limit 10";

$result = @mysql_query($query, $conn) or die ("Заявката неможе да бъде изпълнена");

while ($row = mysql_fetch_array($result))

{

?>

<table border="1" width="100%">

<th align="left">От: <?php echo $row['name']; ?></th>

<tr>

<th align="left">Email: <?php echo $row['email']; ?></th>

</tr>

<tr>

<td><?php echo $row['komentar']; ?></td>

</tr>

<tr>

<td class="td">Дата: <?php echo $row['vreme']; ?></td>

</tr>

</table>

<hr>

<?php } ?>

</body>

</html>


Script by relax4o