Форум, работающий с базой данных MySQL
Редактирование сообщения может понадобиться,если пользователь допустил ошибку, или хочет изменить что-нибудь в тексте. Редактировать можно только свои сообщения, за этим следит скрипт и БД.В зависимости от того, является сообщение топиком или ответом на топик, выводятся 2 разные формы.
connect ();
//
if ($type=="message") {
$query="select message from topics where name='$nick' and top_name='$top_name'";
$result=mysql_query ($query);
$row=mysql_fetch_array ($result);
$message=$row["message"];
$message=str_replace ("<br>","",$message);
print_header ();
//
?>
<h3 alignОnter><font color="0000ff">Edit message.</font></h3>
<p align=right>| <a href="<?php echo $script ?>">Go to topics</a> | <a href="<?php echo $script ?>?action=register"> Register</a> |
<p align=right><font color="0000ff"> Only registered users may post messages in this forum.</font>
<p><form action="<?php echo $script ?>" name="editmsg" method="GET">
<table width`% alignОnter bgcolor="aaaaaa">
<tr><td>
<tr><td><b>Your nick:</b><td>
<input type="text" name="name" size >
<tr><td><b>Your password:</b><td> <input type="password" name="passwd" size >
<tr><td colspan=2> <b>Message:</b><p> <textarea cols@ rows WRAP 80="virtual" name="post">
<?php echo $message ?><br></textarea>
<tr><td colspan=2> <input type="hidden" name="action" value="edit">
<tr><td colspan=2> <input type="hidden" name="submit" value="1">
<tr><td colspan=2> <input type="hidden" name="top_name" value="<?php echo $top_name ?>">
<tr><td colspan=2> <input type="hidden" name="nick" value="<?php echo $nick ?>">
<tr><td colspan=2> <input type="hidden" name="type" value="<?php echo $type ?>">
<tr><td colspan=2> <input type="hidden" name="reply_date" value="<?php echo $reply_date ?>">
<tr><td colspan=2 alignОnter> <br><input type="submit" value="Submit"></table>
<?php
} elseif ($type=="reply") {
//
$query="select reply from replies where name ='$nick' and top_name='$top_name' and reply_date='$reply_date'";
$result=mysql_query ($query);
$row=mysql_fetch_array ($result);
$reply=$row["reply"];
$reply=str_replace ("<br>","",$reply);
print_header ();
?>
<h3 alignОnter><font color="0000ff">Edit reply.</font></h3>
<p align=right>| <a href="<?php echo $script ?>">Go to topics</a> | <a href="<?php echo $script ?>?action=register"> Register</a> |
<p align=right><font color="0000ff"> Only registered users may post messages in this forum.</font>
<p><form action="<?php echo $script ?>" name="editmsg" method="GET">
<table width`% alignОnter bgcolor="aaaaaa">
<tr><td>
<tr><td><b>Your nick:</b><td> <input type="text" name="name" size >
<tr><td><b>Your password:</b><td> <input type="password" name="passwd" size >
<tr><td colspan=2> <b>Message:</b><p> <textarea cols@ rows WRAP 80="virtual" name="post">
<?php echo $reply ?><br></textarea>
<tr><td colspan=2> <input type="hidden" name="action" value="edit">
<tr><td colspan=2> <input type="hidden" name="submit" value="1">
<tr><td colspan=2> <input type="hidden" name="top_name" value="<?php echo $top_name ?>">
<tr><td colspan=2> <input type="hidden" name="nick" value="<?php echo $nick ?>">
<tr><td colspan=2> <input type="hidden" name="type" value="<?php echo $type ?>">
<tr><td colspan=2> <input type="hidden" name="reply_date" value="<?php echo $reply_date ?>">
<tr><td colspan=2 alignОnter> <br> <input type="submit" value="Submit"></table>
<?php
}
}
Далее,можно считать и обработать данные.
elseif ($action=="edit") {
if ($submit) {
connect ();
//
$dateЪte ( "Y-m-d H:i:s",mktime ());
$end="\n----------------------------------------------------------\n This message was edited by $nick $date.";
$post=str_replace ("'"," ",$post);
$post.=$end;
$post=htmlspecialchars ($post);
$post=nl2br ($post);
//
if ($type=="message") {
$query="select id from info where name='$name' and password='$passwd'";
$result=mysql_query ($query);
//
if (mysql_num_rows ($result) && $name==$nick) {
$query="update topics set message='$post' where top_name='$top_name'";
$result=mysql_query ($query);
print_header ();
?>
//
<h3 alignОnter>Thank you,<font color='ff0000'><?php echo $nick ?></font>!</h3>
<p>Your message was changed.
<p><center>| <a href="<?php echo $script ?>">Go to topics</a> | <a href="<?php echo $script ?>?actiond_new_top"> Post new topic</a> |</center>
<?php
} else {
print_header ();
?>
//
<h3 alignОnter>Error!</h3>
<p>This message cannot be edited.May be you entered incorrect nick or password,
or you are not an author of this message.
<p>Please,go back and try again.
<p><center>| <a href='javascript:history.back ()'> Go back</a>| <a href="<?php echo $script ?>">Go to topics</a> |</center>
<?php
}
} elseif ($type=="reply") {
//
$query="select id from info where name='$name' and password='$passwd'";
$result=mysql_query ($query);
if (mysql_num_rows ($result) && $name==$nick) {
$query="update replies set reply='$post' where top_name='$top_name' and name='$nick' and reply_date='$reply_date'";
$result=mysql_query ($query);
print_header ();
?>
<h3 alignОnter>Thank you,<font color='ff0000'> <?php echo $nick ?></font>!</h3>
<p>Your message was changed.
<p><center>| <a href="<?php echo $script ?>">Go to topics</a> |<a href="<?php echo $script ?>?actiond_new_top"> Post new topic</a> |</center>
<?php
} else {
print_header ();
?>
<h3 alignОnter>Error!</h3>
<p>This message cannot be edited.May be you entered incorrect nick or password,
or you are not an author of this message.
<p>Please,go back and try again.
<p><center>| <a href='javascript:history.back ()'> Go back</a>| <a href="<?php echo $script ?>">Go to topics</a> |</center>
<?php
}
}
}
Как видите,ничего нового.Те же SQL-запросы в связке с PHP-функциями.
|
|