I have the following PHP script to update the blog view
in my database,
<?php include('header.php'); ?>
<?php
$article_id = $_POST['article'];
// echo $article_id;
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$con = mysql_connect($dbhost, $dbuser , $dbpass);
$sql = 'SELECT id,blog_title, blog_body, views FROM tinyblog where id="'. $article_id .'" ';
// UPDATE VIEWS.
mysql_query("UPDATE tinyblog SET views = views + 1 WHERE id = {$article_id}" , $con );
mysql_select_db('tinyblog');
$retval = mysql_query( $sql, $con );
if(! $retval ) {
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
?>
<div class="article-blog-indiv">
<?php
echo '<h1>'. $row['blog_title'] .'</h1>';
echo '<p>'. $row['blog_body'] .'</p>';
?>
</div>
<?php
}
?>
<?php include('footer.php'); ?>
It is the following line of code that actually updates the views field in my database:
mysql_query("UPDATE tinyblog SET views = views + 1 WHERE id = {$article_id}" , $con );
Now this line of code does't seem to work , as every time i go back and check in phpmyadmin, i see that the views field is still 0
, But when i insert the following statement directly for testing my my phpmyadmin:
mysql_query("UPDATE tinyblog SET views = views + 1 WHERE id = 1);
I see an increment in the views field , why is this happening ??
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…