Jump to content

Problem with Commenting Script


DiscoTrio

Recommended Posts

Alright, I created a really nice 61 line commenting script.  Everything works up untill it gets to the part where a new comment is added.  Adding part starts at line 36.  I dont ge any errors.  Everything suggests that it works but nothing is in the database.  All table names ave been triple checked.

 

<? $myFile = "username.txt";
$fh = fopen($myFile, 'r');
$username = fread($fh, 40);
fclose($fh); ?>
<?php
$con = mysql_connect("localhost","bmvybfbk_master","*******");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("bmvybfbk_website", $con);
$result = mysql_query("SELECT * FROM comments WHERE journalid = '$username' ORDER BY id  DESC");
while($row = mysql_fetch_array($result))
{
  $comment = $row['comment'];
    $writer = $row['writer'];
        $commentnumber = $row['id'];
  echo "<br><a href='http://www.robloxianjournal.com/$writer'><font face='Papyrus' size='4'>$writer</font></a> said:";
echo "<br>" . $row['comment'];
//echo "<a href='commentflag.php?id=$commentnumber'><font face='Papyrus' size='2'>Report Abuse</font></a>";
echo "<br>";
}
?>
<?
$db = mysql_select_db ("bmvybfbk_website",$con) or die ("Cannot connect to database");
$sql_query = "SELECT * FROM comments WHERE journalid = '$username'";
$result = mysql_query($sql_query);
$rows = mysql_num_rows($result);
?>
<? if($rows == 0){
echo "No Comments";
}else{
echo "";
}
?>
<p><form method=post action=index.php?action=commentsend  name=s>
<table>
</td></tr>
<tr><td></td><td>Comment-<br><textarea name="message" id="message" style="width:300px;height:150px;">
</textarea></td></tr>
<tr><td colspan=2 align=left><input type=submit value=Send></td></tr>
</table>
</form>
<?php
$con = mysql_connect("localhost","bmvybfbk_master","*******");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("bmvybfbk_website", $con);
if (!$message) {
exit;
}
if ($action == commentsend) {

mysql_query ("INSERT INTO `comments` (`writer` ,`comment` ,`journalid`)VALUES ('$session->username', '$message', '$username');");

echo "Message Sent";
}
mysql_close($con);
?> 

Link to comment
https://forums.phpfreaks.com/topic/182535-problem-with-commenting-script/
Share on other sites

For debugging purposes it's usually a good idea to put error_reporting(E_ALL); at the top of your script.

 

Just glancing at your code I think your error is probably here:

 

if ($action == commentsend) {

 

I think what you want is:

 

if ($_GET['action'] == 'commentsend') {

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.