Nexus Zero Posted July 29, 2007 Share Posted July 29, 2007 This following code snippet successfully takes a specific entry from the "comments" table and dumps it into the $row array. The 'if' statement looks at a $_GET value which, if set to 'up', takes an integer from this array, increases it, and is meant to write it back to the database. While the code does increase this integer (revealed when using echo lines), it doesn't seem to write the number back to the database, or if it does, not in the right place. $result = mysql_query("SELECT * FROM comments WHERE commentsID=$commentsid"); $row = mysql_fetch_array($result); if($judgement=="up") { $insert = $row['Rank']++; mysql_query("INSERT INTO comments ('Rank') VALUES ($insert)"); Any help will be much appreciated! Link to comment https://forums.phpfreaks.com/topic/62345-solved-trouble-writing-to-database/ Share on other sites More sharing options...
Barand Posted July 29, 2007 Share Posted July 29, 2007 try $insert = ++$row['Rank']; $var++ returns value then increments Link to comment https://forums.phpfreaks.com/topic/62345-solved-trouble-writing-to-database/#findComment-310250 Share on other sites More sharing options...
Nexus Zero Posted July 29, 2007 Author Share Posted July 29, 2007 Thanks for the quick reply. Unfortunately, that didn't seem to work either. After the increment, both $insert and $row['Rank'] are 1 (as opposed to 0 before). It's a matter of writing it to the database in the correct way, though I don't see what's going wrong. Link to comment https://forums.phpfreaks.com/topic/62345-solved-trouble-writing-to-database/#findComment-310262 Share on other sites More sharing options...
Barand Posted July 29, 2007 Share Posted July 29, 2007 result = mysql_query("SELECT * FROM comments WHERE commentsID=$commentsid"); $row = mysql_fetch_array($result); if($judgement=="up") { mysql_query("UPDATE comments SET Rank = Rank + 1 WHERE commentsID=$commentsid"); } Link to comment https://forums.phpfreaks.com/topic/62345-solved-trouble-writing-to-database/#findComment-310266 Share on other sites More sharing options...
Nexus Zero Posted July 29, 2007 Author Share Posted July 29, 2007 That's fantastic, works perfectly and I've learned a little something too Many thanks. Link to comment https://forums.phpfreaks.com/topic/62345-solved-trouble-writing-to-database/#findComment-310448 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.