Code not incrementing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Code not incrementing

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

UPDATE threads SET replies = replies + 1 WHERE id = '$thread'
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post by Archy »

Hmm, it still seems to stop on 2 :\
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it'll only update the $thread you give it.
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post by Archy »

I know, but it still aint incrementing like it should :P
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what's your code now?
Archy
Forum Contributor
Posts: 129
Joined: Fri Jun 18, 2004 2:25 pm
Location: USA

Post 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
Post Reply