Hi everybody,
the below is the code of my comment.php file, which processes the comments which are posted on view_post.php
if the link is like localhost/phpblog/view_post.php?id=5 and you post a comment on that page, it stores the comment in DB, and refreshes the page with the current comment on it, which is perfect.
The problem is I uploaded it on live site, with the database. Everything works, but once you click on "Add Comment" button, it sends message to administrator, but can't refresh the page since it can't find id. I don't know why?...
The below are my comment.php and view_post.php files which work great on my localhost. And this is the link where you can see the problem: http://dhost.info/ickball/phpblog/view_post.php?id=5 if you just try to post any dummy comment, you would understand what I'm saying.
Thanks,
Ikbol
//comment.php
<?php
include("blocks/bd.php");
if (isset($_POST['author'])) {
$author = $_POST['author'];
}
if (isset($_POST['text'])) {
$text = $_POST['text'];
}
if (isset($_POST['check'])) {
$check = $_POST['check'];
}
if (isset($_POST['sub_com'])) {
$sub_com = $_POST['sub_com'];
}
if (isset($_POST['id'])) {
$id = $_POST['id'];
}
if (isset($sub_com)) {
if (isset($author)) {
trim($author);
}else {
$author == "";
}
if (isset($text)) {
trim($text);
}else {
$text == "";
}
if (empty($author) or empty($text)) {
exit("<p>Please <a href='view_post.php?id=$id'>go back </a> and fill all the fields.</p>");
}
$author = stripslashes($author);
$text = stripslashes($text);
$author = htmlspecialchars($author);
$text = htmlspecialchars($text);
$result = mysql_query("SELECT sum FROM comments_settings");
$myrow = mysql_fetch_array($result);
if ($check == $myrow['sum']) {
$date = date("Y-m-d");
$result2 = mysql_query("INSERT INTO comments (author, date, post_id, text) values ('$author', '$date', '$id', '$text')");
$address = "valijanovich@gmail.com";
$subject = "A new comment on your blog";
$result3 = mysql_query("SELECT title FROM data WHERE id = '$id'");
$myrow3 = mysql_fetch_array($result3);
$post_title = $myrow3['title'];
$message = "A new comment has been added to - ".$post_title."\nAdded by: ".$author."\nContent: ".$text."\nFollow the post: http://localhost/phpblog/view_post.php?id=".$id."";
mail($address, $subject, $message, "content-type: text/plain; Charset=windows-1251 \r\n");
echo "<html><head><meta http-equiv='Refresh' content='0; URL=view_post.php?id=$id'></head></html>";
exit();
}else {
exit("<p>Please <a href='view_post.php?id=$id'>go back </a> and make sure you've entered the right sum.</p>");
}
}
?>
//view_post.php
<?php
include ("blocks/bd.php");
if (isset($_GET['id'])) {
$id = $_GET['id'];
}
if (!isset($id)) {
$id = 1;
}
$result = mysql_query("SELECT * FROM data WHERE id='$id'");
if (!$result) {
echo "<p>Query can't be processed, please tell administrator about this error: valijanovich@gmail.com<br>Error code:</p>";
exit (mysql_error());
}
if (mysql_num_rows($result)>0) {
$myrow = mysql_fetch_array($result);
$new_view = $myrow['view'] + 1;
$update = mysql_query("UPDATE data SET view='$new_view' WHERE id='$id'");
}else {
echo "<p>There is no information in DataBase to display on this page</p>";
exit();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<meta name="description" content="<?php echo $myrow['meta_d']; ?>">
<meta name="keywords" content="<?php echo $myrow['meta_k']; ?>">
<title>
<?php
echo $myrow['title'];
?>
</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="690" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" class="main_border">
<?php
include ("blocks/header.php");
?>
<tr>
<td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<?php
include ("blocks/lefttd.php");
?>
<td valign="top">
<?php
printf("<p class='post_title2'>%s</p><p class='post_author_date_views'>Author: %s</p><p class='post_author_date_views'>Date added: %s</p>%s<p class='post_author_date_views'>Views: %s</p>",$myrow['title'], $myrow['author'], $myrow['date'], $myrow['text'], $myrow['view']);
echo "<p class='comment_title'>Comments:</p>";
$result3 = mysql_query("SELECT * FROM comments WHERE post_id = '$id'");
$myrow3 = mysql_fetch_array($result3);
if (mysql_num_rows($result3)>0) {
do {
printf("<div class='comment_div'><p class='post_adds'>Added by: <strong>%s</strong> <br>Date: <strong>%s</strong></p><p>%s</p></div>", $myrow3['author'], $myrow3['date'], $myrow3['text'] );
} while ($myrow3 = mysql_fetch_array($result3));
}
$result4 = mysql_query("SELECT img FROM comments_settings");
$myrow4 = mysql_fetch_array($result4);
?>
<p class="comment_title">Leave your comment</p>
<form action="comment.php" method="POST">
<p><label>Your name: </label>
<input type="text" name="author" size="30" maxlength="40">
</p>
<p>
<label>Your comment: <br>
<textarea name="text" cols=32" rows="4">
</textarea>
</label>
</p>
<p>Enter the sum:<br>
<img style="margin-top:1px;" src="<?php echo $myrow4['img']; ?>" width="80" height="40">
<input style="margin-bottom:14px;" type="text" name="check" size="7">
</p>
<input name="id" type="hidden" value="<?php echo $id; ?>">
<p>
<input type="submit" name="sub_com" value="Add Comment">
</p>
</form>
</td>
</tr>
</table></td>
</tr>
<?php
include ("blocks/footer.php");
?>
</table>
</body>
</html>
Help please with the URL issue
Moderator: General Moderators
-
ikbolkobulov
- Forum Newbie
- Posts: 1
- Joined: Wed Dec 16, 2009 1:15 am