I'm following this tutorial. It's the third part of the three part tutorial. I did the first 2 parts just fine after some tweaking.
So, here's my problem with the tutorial. It's a news script with comments. Let me list the code here:
readcomments.php
PHP Code:
<HTML>
<HEAD>
<LINK rel="stylesheet" type="text/css" href="style.css">
</HEAD>
<BODY>
<?php
include ('dbconfig.php');
$id = strip_tags($_GET["id"]);
$q = "SELECT * from blog_comments where blog_id='$id' order by date desc ";
$result= mysql_query($q) or die
("Could not execute query : $q." . mysql_error());
while ($row=mysql_fetch_array($result))
{
$id=$row["id"];
$name=$row["name"];
$email=$row["email"];
$entry=$row["entry"];
$date=$row["date"];
$blog_id = $row["blog_id"];
?>
<table width="80%" border="0" cellspacing="1" cellpadding="0" align="center">
<tr>
<td>Comments for <?php echo "$title"; ?></td>
</tr>
<tr>
<td>
<?php echo "$entry"; ?>
<p>Posted by <a href="mailto:<?php echo "$email"; ?>"><?php echo "$name"; ?> on <?php echo "$date"; ?>.</p>
</td>
</tr>
</table>
<?php
}
// display write comments HTML here.
?><p align="center"><a href="<?php echo "addcomments.php?id=$blog_id"; ?>">Add Comments</a></p>
</BODY>
</HTML>
addcomments.php
PHP Code:
<HTML>
<HEAD>
<LINK rel="stylesheet" type="text/css" href="style.css">
</HEAD>
<BODY>
<?php
include ('dbconfig.php');
$action = strip_tags($_GET["action"]);
$id = strip_tags($_GET["id"]);
if ($action=="add")
{
$name = strip_tags($_POST["name"]);
$entry = strip_tags($_POST["entry"]);
$email = strip_tags($_POST["email"]);
// add comments
if (empty($name) || empty($entry))
{
die ("Error, you cannot submit a blank entry.");
}
$q = "insert into blog_comments (id, name, email, date, blog_id, entry) VALUES ('','$name','$email',now(),'$id','$entry')";
$result= mysql_query($q) or die
("Could not execute query : $q." . mysql_error());
if ($result)
{
echo "Success. Comments has been added.";
echo "<p>Click <a href=\"readcomments.php?id=$id\">here</a> to read.</p>";
}
}
else {
?><form action="<?php echo "addcomments.php?action=add&id=$id"; ?>" method="post">
<table width="130" border="1" cellspacing="2" cellpadding="3" bordercolor="gray">
<tr>
<td height="23" colspan="2"><b>Add Comments</b></td>
</tr>
<tr>
<td>Name:*</td>
<td>
<input type="text" name="name" size="30">
</td>
</tr>
<tr>
<td height="25">Email:</td>
<td height="25">
<input type="text" name="email" size="30">
</td>
</tr>
<tr>
<td height="25">Comments:*</td>
<td height="25">
<textarea name="entry" cols="30" rows="5"></textarea>
</td>
</tr>
<tr><td colspan=2><input type="submit" value="submit"></td></tr>
</table></form>
<?php
}
?>
</BODY>
</HTML>
part of index.php
PHP Code:
<!-- Start News -->
<?php
include ('dbconfig.php');
$q = "SELECT * from blog order by date desc ";
$result= mysql_query($q, $connection) or die
("Could not execute query : $q." . mysql_error());
// dynamic navigation variables
$rows_per_page=5; // adjust the number here to display number of entries per page
$total_records=mysql_num_rows($result);
$pages = ceil($total_records / $rows_per_page);
$screen = $_GET["screen"];
if (!isset($screen))
$screen=0;
$start = $screen * $rows_per_page;
$q .= "LIMIT $start, $rows_per_page";
$result= mysql_query($q, $connection) or die
("Could not execute query : $q." . mysql_error());
while ($row=mysql_fetch_array($result))
{
$id=$row["id"];
$name=$row["name"];
$email=$row["email"];
$entry=$row["entry"];
$date=$row["date"];
$icon=$row["icon"];
$title=$row["title"];
?>
<span><?php echo "$title"; ?> on <?php echo "$date"; ?></span>
<BR>
<IMG src="<?php echo "$icon"; ?>" alt="LemmonLime" align="left">
<?php echo "$entry"; ?><BR>
<TABLE cellpadding="2" cellspacing="1" border="0" width="100%">
<TR>
<TD><A href="mailto:<?php echo "$email"; ?>"><?php echo "$name"; ?></A></TD>
<TD>
<?php
$query = "select id from blog_comments where blog_id='$id' ";
$ret = mysql_query($query) or die (mysql_error());
$comment_num = mysql_num_rows($ret);
// display number of comments
echo "<a href=\"readcomments.php?id=$id\">$comment_num</a>";
?>
I can see the page (readcomments.php) just fine with the right comment id for the news id, but when I click Add Comments on that page I go to addcomments.php?id=. So the id is non-existant. I've played around with the quotes (which I thought was probably the problem) but it didn't solve the problem.
Any help would be appreciated! I bet it's probably just something real easy and I'll be embarrased when someone tells me. 
|