Glenskie Posted February 6, 2012 Share Posted February 6, 2012 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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/256518-comments-not-working/ Share on other sites More sharing options...
darkfreaks Posted February 6, 2012 Share Posted February 6, 2012 the way you are doing it is for MSSQL not MYSQL otherwise you need something like INSERT INTO 'sometable' VALUES (value1,value2,value3) Quote Link to comment https://forums.phpfreaks.com/topic/256518-comments-not-working/#findComment-1315030 Share on other sites More sharing options...
trq Posted February 6, 2012 Share Posted February 6, 2012 the way you are doing it is for MSSQL not MYSQL Both styles are valid SQL and will work in MySQL. Quote Link to comment https://forums.phpfreaks.com/topic/256518-comments-not-working/#findComment-1315046 Share on other sites More sharing options...
PFMaBiSmAd Posted February 6, 2012 Share Posted February 6, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/256518-comments-not-working/#findComment-1315069 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.