From 1cb945e201704062e9940f327464f4b31a861f20 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Mon, 5 Jan 2009 21:48:01 -0500 Subject: Changed comments' user index Previously, the comments table referenced users by username. However, if user ever changed their username, everything would become messed up. To fix this, the index has been changed to the user ID. This change obviously requires maintenance: This SQL must be run: "ALTER TABLE `comments` ADD `user_id` INT( 11 ) NOT NULL AFTER `page_id`;" This PHP will generate some SQL that must be run: "); } $getusers = "SELECT * FROM anon_commenters"; $getusers2 = mysql_query($getusers); while ($getusers3 = mysql_fetch_array($getusers2)) { echo("UPDATE comments SET user_id = " . $getusers3['id'] . " WHERE username = \"" . $getusers3['username'] . "\" AND is_anon = 1;
"); } ?> This SQL must be run: "ALTER TABLE `comments` DROP `username`;" --- pages/admin.php | 2 +- pages/post.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'pages') diff --git a/pages/admin.php b/pages/admin.php index fda03c3..12a2d01 100755 --- a/pages/admin.php +++ b/pages/admin.php @@ -563,7 +563,7 @@ if (isLoggedIn()) $insanon = "INSERT INTO anon_commenters (username,email,website) VALUES (\"" . $getcomment3['author'] . "\",\"" . $getcomment3['email'] . "\",\"" . $getcomment3['website'] . "\")"; $insanon2 = mysql_query($insanon); - $inscomment = "INSERT INTO comments (page_id,username,comment,is_anon) VALUES (\"" . $getcomment3['page_id'] . "\",\"" . $getcomment3['author'] . "\",\"" . $getcomment3['comment'] . "\",1)"; + $inscomment = "INSERT INTO comments (page_id,user_id,comment,is_anon) VALUES (\"" . $getcomment3['page_id'] . "\"," . mysql_insert_id() . ",\"" . $getcomment3['comment'] . "\",1)"; $inscomment2 = mysql_query($inscomment); $delcomment = "DELETE FROM moderation WHERE id = " . $getcomment3['id']; diff --git a/pages/post.php b/pages/post.php index 7d6dd08..87413e8 100755 --- a/pages/post.php +++ b/pages/post.php @@ -56,7 +56,7 @@ if (!isset($_GET['id'])) { if ($getanon3['email'] == $_POST['email']) { - $setcomment = "INSERT INTO comments SET page_id = \"" . $_GET['id'] . "\", username = \"" . $_POST['username'] . "\", comment = \"" . $_POST['comment'] . "\", is_anon = 1"; + $setcomment = "INSERT INTO comments SET page_id = \"" . $_GET['id'] . "\", user_id = " . $getanon3['id'] . ", comment = \"" . $_POST['comment'] . "\", is_anon = 1"; $setcomment2 = mysql_query($setcomment); $page_id = $_GET['id']; @@ -84,7 +84,7 @@ if (!isset($_GET['id'])) } } } else { - $setcomment = "INSERT INTO comments SET page_id = \"" . $_GET['id'] . "\", username = \"" . getSessionUsername() . "\", comment = \"" . $_POST['comment'] . "\", is_anon = 0"; + $setcomment = "INSERT INTO comments SET page_id = \"" . $_GET['id'] . "\", user_id = " . getSessionUserID() . ", comment = \"" . $_POST['comment'] . "\", is_anon = 0"; $setcomment2 = mysql_query($setcomment); mail('hatkirby@fourisland.com', 'New comment on Four Island!', getSessionUsername() . ' has posted a comment on Four Island under the "page id" ' . $_GET['id']); -- cgit 1.4.1