Help - Search - Members - Calendar
Full Version: [resolved] Allowing User Comments
Codegrrl.com Forums > Script Help > Tutorial Help
Billy
Eep. Got another error.

QUOTE

<?php include 'hdr.php'; ?>

<?php
mysql_connect ('localhost', 'username', 'pw') ;
mysql_select_db ('database');

$sql = "SELECT * FROM php_journal ORDER BY timestamp DESC LIMIT 5";

$result = mysql_query($sql) or print ("Can't select entries from table php_journal.<br />" . $sql . "<br />" . mysql_error());

while($row = mysql_fetch_array($result)) {

$date = date("l F d Y", $row['timestamp']);

$title = stripslashes($row['title']);
$entry = stripslashes($row['entry']);
$mood = stripslashes($row['mood']);
$music = stripslashes($row['music']);
?>

<p><strong><?php echo $title; ?></strong><br /><br />
<?php echo $entry; ?><br /><br />
Rocked on <?php echo $date; ?><Br>
Currently feeling <?php echo $mood; ?><br>
Dancing to <?php echo $music; ?><br/><br/>
<?php

$result2 = mysql_query ("SELECT id FROM php_journal_comments WHERE entry='$id'");
$num_rows = mysql_num_rows($result2);

if ($num_rows > 0) {
echo "<a href=\"journal.php?id=" . $id . "\">" . $num_rows . " Mundane Thoughts</a>";
}
else {
echo "<a href=\"journal.php?id=" . $id . "\">Walk and Talk</a>";
} ?>
<hr /></p>

<?php
}


$id = $row['id'];
$commenttimestamp = strtotime("now");

$sql = "SELECT * FROM php_journal_comments WHERE entry='$id' ORDER BY timestamp";
$result = mysql_query ($sql) or print ("Can't select comments from table php_journal_comments.<br />" . $sql . "<br />" . mysql_error());
while($row = mysql_fetch_array($result)) {
$timestamp = date("l F d Y", $row['timestamp']);
printf("<hr />");
print("<p>" . stripslashes($row['comment']) . "</p>");
printf("<p>Comment by <a href=\"%s\">%s</a> @ %s</p>", stripslashes($row['url']), stripslashes($row['name']), $timestamp);
printf("<hr />");
}

<form method="post" action="/dstrbnglywrd/process.php">
<p><input type="hidden" name="entry" id="entry" value="<?php echo $id; ?>" />
<input type="hidden" name="timestamp" id="timestamp" value="<?php echo $commenttimestamp; ?>">

<strong><label for="name">Name:</label></strong> <input type="text" name="name" id="name" size="25" /><br />
<strong><label for="email">E-mail:</label></strong> <input type="text" name="email" id="email" size="25" /><br />
<strong><label for="url">URL:</label></strong> <input type="text" name="url" id="url" size="25" value="http://" /><br />
<strong><label for="comment">Comment:</label></strong><br />

<textarea cols="25" rows="5" name="comment" id="comment"></textarea></p>

<p><input type="submit" name="submit_comment" id="submit_comment" value="Add Comment" /></p>
</form>
}
?>
</div>
<?php include 'ftr.php'; ?>


It keeps showing this message:
Parse error: syntax error, unexpected '<' in /home/iheartyo/public_html/shotgundeathwish/index.php on line 57
Amelie
You need to "close" PHP before the HTML comment form starts.

Add ?> above this part:

CODE
<form method="post" action="/dstrbnglywrd/process.php">


And change this part:

CODE
</form>
}
?>


To:

CODE
</form>
<?php
}
?>
Billy
I did what you said and it replied:

Parse error: syntax error, unexpected '}' in /home/iheartyo/public_html/shotgundeathwish/index.php on line 73
Amelie
Can you post your code as it is now? I added the modifications to what you posted above, but I didn't get an error.
Billy
QUOTE

<?php include 'hdr.php'; ?>
<div class="grunge">

<?php
mysql_connect ('localhost', 'name', 'pw') ;
mysql_select_db ('db');

$sql = "SELECT * FROM php_journal ORDER BY timestamp DESC LIMIT 5";

$result = mysql_query($sql) or print ("Can't select entries from table php_journal.<br />" . $sql . "<br />" . mysql_error());

while($row = mysql_fetch_array($result)) {

$date = date("l F d Y", $row['timestamp']);

$title = stripslashes($row['title']);
$entry = stripslashes($row['entry']);
$mood = stripslashes($row['mood']);
$music = stripslashes($row['music']);
?>

<p><strong><?php echo $title; ?></strong><br /><br />
<?php echo $entry; ?><br /><br />
Rocked on <?php echo $date; ?><Br>
Currently feeling <?php echo $mood; ?><br>
Dancing to <?php echo $music; ?><br/><br/>
<?php

$result2 = mysql_query ("SELECT id FROM php_journal_comments WHERE entry='$id'");
$num_rows = mysql_num_rows($result2);

if ($num_rows > 0) {
echo "<a href=\"journal.php?id=" . $id . "\">" . $num_rows . " Mundane Thoughts</a>";
}
else {
echo "<a href=\"journal.php?id=" . $id . "\">Walk and Talk</a>";
} ?>
<hr /></p>

<?php
}


$id = $row['id'];
$commenttimestamp = strtotime("now");

$sql = "SELECT * FROM php_journal_comments WHERE entry='$id' ORDER BY timestamp";
$result = mysql_query ($sql) or print ("Can't select comments from table php_journal_comments.<br />" . $sql . "<br />" . mysql_error());
while($row = mysql_fetch_array($result)) {
$timestamp = date("l F d Y", $row['timestamp']);
printf("<hr />");
print("<p>" . stripslashes($row['comment']) . "</p>");
printf("<p>Comment by <a href=\"%s\">%s</a> @ %s</p>", stripslashes($row['url']), stripslashes($row['name']), $timestamp);
printf("<hr />");
}

?>
<form method="post" action="/dstrbnglywrd/process.php">
<p><input type="hidden" name="entry" id="entry" value="<?php echo $id; ?>" />
<input type="hidden" name="timestamp" id="timestamp" value="<?php echo $commenttimestamp; ?>">

<strong><label for="name">Name:</label></strong> <input type="text" name="name" id="name" size="25" /><br />
<strong><label for="email">E-mail:</label></strong> <input type="text" name="email" id="email" size="25" /><br />
<strong><label for="url">URL:</label></strong> <input type="text" name="url" id="url" size="25" value="http://" /><br />
<strong><label for="comment">Comment:</label></strong><br />

<textarea cols="25" rows="5" name="comment" id="comment"></textarea></p>

<p><input type="submit" name="submit_comment" id="submit_comment" value="Add Comment" /></p>
</form>

<?php
}
?>

</div>
<?php include 'ftr.php'; ?>
Amelie
Looks like you don't need this bit at the end:

CODE
<?php
}
?>


Delete that and it should work.
Billy
Thanks a bunch Amelie! ^^ *goes off to join your fanlisting*
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.