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
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') {

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.