waverider303 Posted December 10, 2009 Share Posted December 10, 2009 I have a commenting system on my website. I have it so that each comment is approved before it is posted live on the site. I have an admin center that displays all the comments and lets me Approve, Disprove, and Ban any comments. I have it set so if you approve it changes the database so that it will display it live. If I Disprove the comment it will delete it from the database. If I Ban it I want to delete it then insert the users IP into another database so that that user cannot post any more comments (sort of a spam filter). This is what I have so far but it does not work and I believe this syntax is invalid. <?php $sql = "DELETE FROM comm WHERE comment_ID = '$comment_id'"; $sql2 = "INSERT INTO `ban_com` (`id`, `usr_ip`) VALUES ('', '$usr_ip')"; if(mysql_query($sql) && mysql_query($sql2)) { echo "<p>Removed Comment</p>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/184672-delete-from-database-then-insert-info-after/ Share on other sites More sharing options...
Maq Posted December 10, 2009 Share Posted December 10, 2009 Instead of deleting then inserting, you can use REPLACE INTO. If the pkey exists it will UPDATE the record, otherwise it will INSERT the new data. Quote Link to comment https://forums.phpfreaks.com/topic/184672-delete-from-database-then-insert-info-after/#findComment-974975 Share on other sites More sharing options...
waverider303 Posted December 10, 2009 Author Share Posted December 10, 2009 Ok Thanks for this. Do you have the syntax that goes along with REPLACE INTO? Quote Link to comment https://forums.phpfreaks.com/topic/184672-delete-from-database-then-insert-info-after/#findComment-974985 Share on other sites More sharing options...
iPixel Posted December 10, 2009 Share Posted December 10, 2009 http://dev.mysql.com/doc/refman/5.0/en/replace.html Quote Link to comment https://forums.phpfreaks.com/topic/184672-delete-from-database-then-insert-info-after/#findComment-974995 Share on other sites More sharing options...
waverider303 Posted December 10, 2009 Author Share Posted December 10, 2009 Ok I have a table that is called COMMENTS inside that table I have a bunch of rows (id, post_id, comment_author, comment_author_email, comment_author_IP, comment_date, comment_content) The primary key in that table is ID and auto_increment. Another table is called BANNED_COMM inside that I just have (id, banned_ip) primary key is ID. I want to delete the entries from COMMENTS and then place only the comment_author_IP into the BANNED_COMM. Do I need something in common with the two tables for this to work? Quote Link to comment https://forums.phpfreaks.com/topic/184672-delete-from-database-then-insert-info-after/#findComment-975022 Share on other sites More sharing options...
waverider303 Posted December 10, 2009 Author Share Posted December 10, 2009 Is this syntax correct? <?php $sql = "REPLACE INTO banned_comm SELECT comment_author_IP FROM comments"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/184672-delete-from-database-then-insert-info-after/#findComment-975036 Share on other sites More sharing options...
waverider303 Posted December 10, 2009 Author Share Posted December 10, 2009 Here is my table layouts: CREATE TABLE `comments` ( `comment_ID` bigint(20) unsigned NOT NULL auto_increment, `comment_post_ID` bigint(20) unsigned NOT NULL default '0', `comment_author` tinytext NOT NULL, `comment_author_email` varchar(100) NOT NULL default '', `comment_author_IP` varchar(100) NOT NULL default '', `comment_date` datetime NOT NULL default '0000-00-00 00:00:00', `comment_date_gmt` datetime NOT NULL default '0000-00-00 00:00:00', `comment_content` text NOT NULL, `comment_approved` enum('Yes','No') NOT NULL default 'No', `comment_agent` varchar(255) NOT NULL default '', PRIMARY KEY (`comment_ID`), KEY `comment_approved` (`comment_approved`), KEY `comment_post_ID` (`comment_post_ID`), KEY `comment_approved_date_gmt` (`comment_approved`,`comment_date_gmt`), KEY `comment_date_gmt` (`comment_date_gmt`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=15 ; CREATE TABLE `banned_comments` ( `id` int(55) NOT NULL auto_increment, `usr_ip` char(15) NOT NULL default '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; Quote Link to comment https://forums.phpfreaks.com/topic/184672-delete-from-database-then-insert-info-after/#findComment-975110 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.