Jump to content

[SOLVED] Trouble writing to database


Nexus Zero

Recommended Posts

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

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.

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");
  }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.