|
|
|
| Добрый день!
Помогите подчинить скрипт комментариев.
Комменты не отправляются. Надпись висит: "Ваш комментарий обрабатывается..." И больше ничего.
<h1>Leave your comment:</h1>
<div id='cerror'></div>
<div align="center">
<form action="#" method="POST" enctype="multipart/form-data" name="addcom" id="addcom" onSubmit="return false">
Your name:<br>
<input name="author" type="text" size="30" class="pole" id="author"><br><br>
Text:<br>
<textarea name="text" rows="5" cols="50" class="text"></textarea><br>
<br>
<input name="id" type="hidden" value="<?php echo $id; ?>">
<input class="adscom" name="button" type="button" value='Add your comment'
onclick="doLoad(document.getElementById('addcom'))">
</form>
|
<?
include_once("blocks/bd.php");
// Запрет на кэширование
header("Expires: Mon, 23 May 1995 02:00:00 GTM");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GTM");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
//****
$log =="";
$error="no"; //флаг наличия ошибки
require_once 'JsHttpRequest.php';
$JsHttpRequest =& new JsHttpRequest("windows-1251");
//Короткие имена переменных и обрезка пробелов img_title
$text = trim($_POST['text']);
$author = trim($_POST['author']);
$id = trim($_POST['id']);
//Проверка email адреса
if($author == ''){
$log .= "Пожалуйста, введите Ваше имя<br>";
$error = "yes";
}
//Проверка наличия введенного текста комментария
if (empty($text)){
$log .= "Необходимо указать текст сообщения!<br>";
$error = "yes";
}
//Экранирование и преобразование опасных символов
if (!get_magic_quotes_gpc()){
$text = addslashes($text);
$author = addslashes($author);
$cod = addslashes($cod);
}
$text = htmlspecialchars($text);
$author = htmlspecialchars($author);
$cod = htmlspecialchars($cod);
//Если нет ошибок добавляем в базу
if($error=="no"){
$date = date("d-m-Y в H:i");
$result2 = mysql_query("INSERT INTO comment (post,author,text,date)
VALUES ('" . mysql_real_escape_string($id) . "','" . mysql_real_escape_string($author) . "','" .
mysql_real_escape_string($text) . "','$date')");
//****
$id = $_REQUEST['id'];
$address = "my@mail.ru";
$subject = "Новый комментарий на сайте";
$post_title = $myrow3["title"];
$message = "Появился комментарий к заметке - ".$post_title."<br>Комментарий добавил(а): ".$author."<br>Текст комментария:
".$text."<br>Ссылка на заметку:'>this is link</a>";
$headers = 'Content-Type: text/html;charset=windows-1251';
mail($address,$subject,$message,$headers);
$ok="<div><strong>".$author."</strong><br>Добавлено: ".$date."<br>".$text."</div>";
//Помещаем результат в массив
$GLOBALS['_RESULT'] = array(
'error' => 'no',
'ok' => $ok
);
}
else {//если ошибки есть
$log = "<div><strong><font color='red'> Ошибка! </font></strong><br>".$log."</div>";
//Отправляем результат в массив
$GLOBALS['_RESULT'] = array(
'error' => 'yes',
'er_mess' => $log);
}
?><?
include_once("blocks/bd.php");
// Запрет на кэширование
header("Expires: Mon, 23 May 1995 02:00:00 GTM");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GTM");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
//****
$log =="";
$error="no"; //флаг наличия ошибки
require_once 'JsHttpRequest.php';
$JsHttpRequest =& new JsHttpRequest("windows-1251");
//Короткие имена переменных и обрезка пробелов img_title
$text = trim($_POST['text']);
$author = trim($_POST['author']);
$id = trim($_POST['id']);
//Проверка email адреса
if($author == ''){
$log .= "Пожалуйста, введите Ваше имя<br>";
$error = "yes";
}
//Проверка наличия введенного текста комментария
if (empty($text)){
$log .= "Необходимо указать текст сообщения!<br>";
$error = "yes";
}
//Экранирование и преобразование опасных символов
if (!get_magic_quotes_gpc()){
$text = addslashes($text);
$author = addslashes($author);
$cod = addslashes($cod);
}
$text = htmlspecialchars($text);
$author = htmlspecialchars($author);
$cod = htmlspecialchars($cod);
//Если нет ошибок добавляем в базу
if($error=="no"){
$date = date("d-m-Y в H:i");
$result2 = mysql_query("INSERT INTO comment (post,author,text,date)
VALUES ('" . mysql_real_escape_string($id) . "','" . mysql_real_escape_string($author) . "','" .
mysql_real_escape_string($text) . "','$date')");
//****
$id = $_REQUEST['id'];
$address = "my@mail.ru";
$subject = "Новый комментарий на сайте";
$post_title = $myrow3["title"];
$message = "Появился комментарий к заметке - ".$post_title."<br>Комментарий добавил(а):
".$author."<br>Текст комментария:
".$text."<br>Ссылка на заметку:'>this is link</a>";
$headers = 'Content-Type: text/html;charset=windows-1251';
mail($address,$subject,$message,$headers);
$ok="<div><strong>".$author."</strong><br>Добавлено: ".$date."<br>".$text."</div>";
//Помещаем результат в массив
$GLOBALS['_RESULT'] = array(
'error' => 'no',
'ok' => $ok
);
}
else {//если ошибки есть
$log = "<div><strong><font color='red'> Ошибка! </font></strong><br>".$log."</div>";
//Отправляем результат в массив
$GLOBALS['_RESULT'] = array(
'error' => 'yes',
'er_mess' => $log);
}
?>
|
// JavaScript Document
function doLoad(value){
err=document.getElementById('cerror');
err.innerHTML = "<img src='images/upload.gif' width='32' height='8'><br>
<p>Ваш комментарий обрабатывается...</p>";
// Create new JsHttpRequest object.
var req = new JsHttpRequest();
// Code automatically called on load finishing.
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.responseJS.error == 'no') {
// Clear error information.
err.innerHTML = "";
// Write req.responseJS to page element (_req.responseJS become responseJS).
err.innerHTML = req.responseJS.ok;
form = document.getElementById('addcom');
form.text.value = "";
form.author.value = "";
}
else
{
err.innerHTML = req.responseJS.er_mess;
}
}
}
// Prepare request object (automatically choose GET or POST).
req.open(null, 'comment_ege.php', true);
// Send data to backend.
req.send( { q: value } );
}
|
| |
|
|