如何让简单的访问者增加PHP?

时间:2017-08-15 13:42:54

标签: php mysql phpmyadmin

我正在尝试在php中创建一个简单的访问者计数器。当我运行它时,我不知道为什么它不会改变而且它保持为1。任何帮助都会欣赏它。

<?php
mysql_connect("localhost","root","")or die ("couldnt connect to database");
mysql_select_db("coursenligne") or die ("couldnt find database");

$find_counts = mysql_query("select * FROM user_counter");
while ($row = mysql_fetch_assoc($find_counts))
{
    $current_counts = $row['counts'];
    $new_count=$current_counts + 1 ;
    $update_count = mysql_query("update `coursenligne`.`user_count` set `counts` = $new_count");
    echo $new_count;
}
?>

  

-- Dumping database structure for coursenligne
CREATE DATABASE IF NOT EXISTS `coursenligne` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
USE `coursenligne`;


-- Dumping structure for table coursenligne.user_counter
CREATE TABLE IF NOT EXISTS `user_counter` (
  `counts` int(11) NOT NULL,
  PRIMARY KEY (`counts`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- Dumping data for table coursenligne.user_counter: ~1 rows (approximately)
/*!40000 ALTER TABLE `user_counter` DISABLE KEYS */;
INSERT INTO `user_counter` (`counts`) VALUES
	(0);

1 个答案:

答案 0 :(得分:1)

您似乎正在尝试更新user_count而不是user_counter