Page 1 of 1

Code not incrementing

Posted: Wed Sep 01, 2004 1:58 pm
by Archy
I am making a forum (basic one :roll:) and at the moment, I am trying to make the replies total increment when someone replies. When they reply, they get taken to a new page where it adds all of the data into a MySQL database, and then updates everything (last post, from whom etc). However, whenever I try and make the replies, and the views increment, They either seem to stay on 1, or stop on 2. I was wondering whether anyone had any idea why this might be hapening.

The code I am using is below, I have tried many ways, even

Code: Select all

replies = '$replies+1'
all with no avail :\

Code: Select all

<?PHP
ob_start();
$conn = mysql_connect('localhost', 'username', 'password');
$rs = mysql_select_db('forum', $conn);
$sql2 = "SELECT * FROM threads";
$rs2 = mysql_query($sql2, $conn);

$row = mysql_fetch_assoc($rs2);
$replies = $row["replies"];
$replies++;
$update = "UPDATE threads SET replies = '$replies' WHERE `id` = '$thread'";
$rs = mysql_query($update) or die(mysql_error());

header("Location: forum.php?area=$area&thread=$thread"); exit();
?>
Thanks

Posted: Wed Sep 01, 2004 2:03 pm
by feyd

Code: Select all

UPDATE threads SET replies = replies + 1 WHERE id = '$thread'

Posted: Wed Sep 01, 2004 2:13 pm
by Archy
Hmm, it still seems to stop on 2 :\

Posted: Wed Sep 01, 2004 2:17 pm
by feyd
it'll only update the $thread you give it.

Posted: Wed Sep 01, 2004 2:22 pm
by Archy
I know, but it still aint incrementing like it should :P

Posted: Wed Sep 01, 2004 2:24 pm
by feyd
what's your code now?

Posted: Wed Sep 01, 2004 2:30 pm
by Archy
OK, it works now, I was using

Code: Select all

UPDATE threads SET replies = $replies + 1 WHERE id = '$thread'
instead of

Code: Select all

UPDATE threads SET replies = replies + 1 WHERE id = '$thread'
I thought you had made a mistake :\

Thanks feyd