razorsese Posted April 3, 2012 Share Posted April 3, 2012 How I can increment a value into database ?! When I try whit my code it's replacing the data from mysql database not summing up $conn = new PDO( DBN, DB_USER, DB_PASS ); $sql = "UPDATE articles SET rating =:rating+1, totalv=:totalv+1 WHERE id = :id"; $st = $conn->prepare ( $sql ); $st->bindValue( ":rating", $this->rating, PDO::PARAM_INT ); $st->bindValue( ":id", $this->id, PDO::PARAM_INT ); $st->bindValue( ":totalv", $this->totalv, PDO::PARAM_INT ); $st->execute(); $conn = null; Link to comment https://forums.phpfreaks.com/topic/260279-php-pdo/ Share on other sites More sharing options...
Jessica Posted April 3, 2012 Share Posted April 3, 2012 You can simplify it a lot by removing the variables for rating and total. you can increment a column by the column name. UPDATE bar SET foo = foo+1 Link to comment https://forums.phpfreaks.com/topic/260279-php-pdo/#findComment-1334032 Share on other sites More sharing options...
razorsese Posted April 3, 2012 Author Share Posted April 3, 2012 Thank you very much Link to comment https://forums.phpfreaks.com/topic/260279-php-pdo/#findComment-1334084 Share on other sites More sharing options...
Jessica Posted April 3, 2012 Share Posted April 3, 2012 you're welcome! Mark as solved! Link to comment https://forums.phpfreaks.com/topic/260279-php-pdo/#findComment-1334096 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.