Показать полную графическую версию : gbook на php
Скажите как мне в гостевой книге сделать так, чтобы
каждое новое сообщение появлялось вверху, а старые ползли бы вниз?
Prisoner
31-03-2005, 20:44
Если предоставишь код гостевой, можно будет говорить о помощи. Просто искать времени нет, да и то ли еще найдешь, вопрос.
Вот:
[MySQL]
create database test;
create table test(name text, pass text);
index.php
=======
<html>
<title></title>
<head>
<META http-equiv=Content-type content="text/html; charset=windows-1251">
<style>
A:link {color: #0099ff; text-decoration: none; font-family: verdana; font-size: 10px; font-weight: bold};
A:visited {color: #0099ff; text-decoration: none; font-family: verdana; font-size: 10px; font-weight: bold};
A:hover {color: #0099ff; text-decoration: underline; font-family: verdana; font-size: 10px; font-weight: bold};
.text {font-family: verdana; font-size: 11px};
</style>
</head>
<body>
<?
$dblocation = "127.0.0.1";
$dbname = "test";
$dbuser = "root";
$dbpassword = "";
if (isset($_GET['user']) && isset($_GET['pass'])){
$a = $_GET['user'];
$s = $_GET['pass'];
$guest = "Гость";
$dbcn = mysql_connect($dblocation, $dbuser, $dbpassword);
$dbsl = mysql_select_db($dbname, $dbcn);
if ($a == "" || $a == " "){
$nik = "Гость";
}else{
$nik = $a;
}
$b = strtolower($s);
$b = str_replace("бля", "fuck", $b);
$b = str_replace("пид", "fuck", $b);
$b = str_replace("пиз", "fuck", $b);
$b = str_replace("пед", "fuck", $b);
$b = str_replace("еба", "fuck", $b);
$b = str_replace("ёба", "fuck", $b);
$b = str_replace("ебн", "fuck", $b);
$b = str_replace("ёбн", "fuck", $b);
$b = htmlspecialchars($b);
if (mysql_query("insert into test values ('$nik', '$b')")){
echo "<html><head>";
echo "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=index.php'>";
echo "</html></head>";
exit();
}
}
?>
<?
$dbcn = mysql_connect($dblocation, $dbuser, $dbpassword);
$dbsl = mysql_select_db($dbname, $dbcn);
$auth = mysql_query("select * from test;");
while ($prnt = mysql_fetch_array($auth)){
echo "<BR><CENTER><table border=0 cellspacing=1 cellpadding=1 bgColor=#0099ff width=300>";
echo "<tr>";
echo "<td align=left bgColor=#ffffff style='font-family: verdana; font-weight: bold; font-size: 10px; color: red'>";
$name = $prnt['name'];
echo "<font color=gray>Написал: </font>".$name."</td>";
echo "</tr>";
echo "<tr height=30 valign=top>";
echo "<td bgColor=#ffffff style='font-family: verdana; font-weight: bold; font-size: 10px; color: #000000'>";
$text = $prnt['pass'];
echo "<P align=justify>".$text."</P></td>";
echo "</tr>";
echo "</table>";
echo "</CENTER><BR>";
}?>
<table align=center>
<tr>
<form action="index.php" method=get>
<td align=center class=text>Ваш ник:<font color=red>*</font></td>
</tr>
<tr>
<td align=center><input type="text" size=25 name="user"></td>
</tr>
<tr>
<td align=center class=text>Сообщение</td>
</tr>
<tr>
<td><textarea rows=5 cols=30 name="pass"></textarea></td>
</tr>
<td align=center><input type="submit" value="Отправить"
style="font-family: verdana; font-size: 11px"></td>
</tr>
</table>
</body></html>
Prisoner
01-04-2005, 15:35
Забавно. в Поле pass, как я понял хранится текст сообщения, так? Тогда неудочно выбранное имя. Ну да ладно. Табличку лучше сделать такой:
CREATE TABLE `messages` (
`m_id` int(5) NOT NULL auto_increment,
`name` varchar(50) NOT NULL default '',
`message` text,
UNIQUE KEY `m_id` (`m_id`),
UNIQUE KEY `name` (`name`)
) TYPE=MyISAM
Код примет вид:
<html>
<title></title>
<head>
<META http-equiv=Content-type content="text/html; charset=windows-1251">
<style>
A:link {color: #0099ff; text-decoration: none; font-family: verdana; font-size: 10px; font-weight: bold};
A:visited {color: #0099ff; text-decoration: none; font-family: verdana; font-size: 10px; font-weight: bold};
A:hover {color: #0099ff; text-decoration: underline; font-family: verdana; font-size: 10px; font-weight: bold};
.text {font-family: verdana; font-size: 11px};
</style>
</head>
<body>
<?
$dblocation = "127.0.0.1";
$dbname = "test";
$dbuser = "root";
$dbpassword = "";
if (isset($_GET['name']) && isset($_GET['mess'])){
$a = $_GET['name'];
$s = $_GET['mess'];
$guest = "Гость";
$dbcn = mysql_connect($dblocation, $dbuser, $dbpassword);
$dbsl = mysql_select_db($dbname, $dbcn);
if ($a == "" || $a == " "){
$nik = "Гость";
}else{
$nik = $a;
}
$b = strtolower($s);
$b = str_replace("бля", "fuck", $b);
$b = str_replace("пид", "fuck", $b);
$b = str_replace("пиз", "fuck", $b);
$b = str_replace("пед", "fuck", $b);
$b = str_replace("еба", "fuck", $b);
$b = str_replace("ёба", "fuck", $b);
$b = str_replace("ебн", "fuck", $b);
$b = str_replace("ёбн", "fuck", $b);
$b = htmlspecialchars($b);
if (mysql_query("insert into test values ('$nik', '$b')")){
echo "<html><head>";
echo "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=index.php'>";
echo "</html></head>";
exit();
}
}
?>
<?
$dbcn = mysql_connect($dblocation, $dbuser, $dbpassword);
$dbsl = mysql_select_db($dbname, $dbcn);
$auth = mysql_query("select name, message from test order by m_id desc");
while ($prnt = mysql_fetch_array($auth)){
echo "<BR><CENTER><table border=0 cellspacing=1 cellpadding=1 bgColor=#0099ff width=300>";
echo "<tr>";
echo "<td align=left bgColor=#ffffff style='font-family: verdana; font-weight: bold; font-size: 10px; color: red'>";
$name = $prnt['name'];
echo "<font color=gray>Написал: </font>".$name."</td>";
echo "</tr>";
echo "<tr height=30 valign=top>";
echo "<td bgColor=#ffffff style='font-family: verdana; font-weight: bold; font-size: 10px; color: #000000'>";
$text = $prnt['message'];
echo "<P align=justify>".$text."</P></td>";
echo "</tr>";
echo "</table>";
echo "</CENTER><BR>";
}?>
<table align=center>
<tr>
<form action="index.php" method=get>
<td align=center class=text>Ваш ник:<font color=red>*</font></td>
</tr>
<tr>
<td align=center><input type="text" size=25 name="user"></td>
</tr>
<tr>
<td align=center class=text>Сообщение</td>
</tr>
<tr>
<td><textarea rows=5 cols=30 name="pass"></textarea></td>
</tr>
<td align=center><input type="submit" value="Отправить"
style="font-family: verdana; font-size: 11px"></td>
</tr>
</table>
</body></html>
$b = str_replace("бля", "fuck", $b);
углубляясь в ... ;)
Есть небольшая прблема.
При добавлении собщения перехожу на страницу с сообщениями,
а когда обновляю страницу, то оно появляется второй раз и т.д.
Скажите , что мне сделать, чтоб этого небыло?
После завершения обработки данных сделать
header("Location: page.html");
Спасибо, всё работает.
А как мне сделать разбиение по страницам,
на каждой например по десять сообщений?
slaine
На http://webscript.ru есть очень подробные и хорошие статьи по этому поводу
© OSzone.net 2001-2012
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.
Available in ZeroNet 1osznRoVratMCN3bFoFpR2pSV5c9z6sTC