我博客中的每篇文章都有一个赞按钮,我想让登录用户只赞一次帖子...
我的数据库中有这三个表:
桌子tbladminXshouts
CREATE TABLE `tbladminXshouts` (
`admin_id` int(20) NOT NULL,
`id` int(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
桌子tbladmin
CREATE TABLE `tbladmin` (
`admin_id` int(11) NOT NULL AUTO_INCREMENT,
`admin_usr_name` varchar(225) NOT NULL,
`admin_pwd` varchar(225) NOT NULL,
PRIMARY KEY (`admin_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=23 ;
桌子shouts
CREATE TABLE `shouts` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
`email` varchar(60) NOT NULL,
`lund` varchar(70) NOT NULL,
`LundaBlogg` varchar(20) NOT NULL,
`date` datetime NOT NULL,
`likes` int(11) NOT NULL,
`post` text NOT NULL,
`ipaddress` varchar(45) NOT NULL,
`userName` varchar(100) NOT NULL,
PRIMARY KEY (`id`),
KEY `email` (`email`),
KEY `lund` (`lund`),
KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=25 ;
现在我使用这个代码,用户可以喜欢多少次他们想要的帖子。我应该写什么 sql 来让我的用户在帖子上只点赞一次?
<?php
class Like
{
function like()
{
if(isset($_POST['Gilla']))
{
$sql="UPDATE shouts SET likes = likes +1 WHERE id = '".$_POST['id']."'";
$result=mysql_query($sql);
}
}
}
?>