Jump to content

comments not working


Glenskie

Recommended Posts

ok here is my script , for some reason , it adds the comment and all it works great , but it wont add it to the notifications table in my database

<?php include("../includes.php");
$session = $logOptions_id;
if($session)
{
$to_id = $_POST['user_id'];
$post_id = $_POST['post_id'];
$comment = mysql_real_escape_string($_POST['comment']);
$date = mktime();
mysql_query("INSERT INTO comments SET user_id='$to_id', from_id='$session', post_id='$post_id', comment='$comment', date='$date'");
$id = mysql_insert_id();



$query = mysql_query("SELECT * FROM comments WHERE post_id='$post_id' AND from_id!='$session' AND state='0' GROUP BY from_id");
if(mysql_num_rows($query)>0)
{
$row1 = mysql_fetch_assoc(mysql_query("SELECT * FROM posts WHERE id='$post_id'"));
$post_from2 = $row1['from_id'];
mysql_query("INSERT INTO notifications SET user_id='$post_from2', from_id='$session', post_id='$id', action_type='4', date='$date'");

while($row = mysql_fetch_array($query))
{
$post_from = $row['from_id'];	
if($post_from!=$post_from2)
{
mysql_query("INSERT INTO notifications SET user_id='$post_from', from_id='$session', post_id='$id', action_type='4', date='$date'");
}
}

}
else
{
$row1 = mysql_fetch_assoc(mysql_query("SELECT * FROM posts WHERE id='$post_id'"));
$post_from = $row1['from_id'];
mysql_query("INSERT INTO notifications SET user_id='$post_from', from_id='$session', post_id='$id', action_type='4', date='$date'");
}

$query = mysql_query("SELECT * FROM comments WHERE id='$id' AND state='0'");
comments($query);
}
?>

Link to comment
https://forums.phpfreaks.com/topic/256518-comments-not-working/
Share on other sites

You have three different INSERT INTO notifications ... queries, inside of conditional logic, in code that isn't indented so that it is readable. Are you sure that your logic is even what you want and that any code with one of the insert queries is even executing? Are you sure that the insert query is not returning an error?

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.