PHP,MYSQL制作投票系统,防止姓名、科室重复

PHP,MYSQL制作投票系统,防止姓名、科室重复,第1张

这个表我觉得还缺个字段啊,还要加个摄影作品id的外键吧

不然你这个表根本就不能记录哪个科的哪个人给哪个作品投了票啊

还有竟然名字有重名,那你就不要存名字,存用户的主键啊

这样就可以避免这个问题

表结构这样就可以了

id pid userid time (pid为摄影作品的id)

投票的时候就判断下

$pid为作品id,前台传过来,用户id存在session中

SELECT COUNT() FROM table WHERE userid='"$_SESSION['userid']"' AND pid='"$pid"'

如果大于0则证明该用户已经给这个作品投票了,因为用户id不可能重复,所以即使用户重名也不影响了

<php

header("Content-type: text/html; charset=utf-8");

$link = mysql_connect( 'localhost', 'root', '') or die('Could not connect to mysql server' );

mysql_select_db('tpxt',$link) or die('Could not select database');

if (isset($_POST['submit'])) {

$sql = "SELECT `id` FROM `table` WHERE `uid` = "$_POST['uid'];

$result = mysql_query($sql);

if ($result && mysql_num_rows($result)) {

$sql = "UPDATE `table` SET `vote`=`vote`+1 WHERE `uid` = "$_POST['uid'];

mysql_query($sql);

}else{

$sql = "INSERT INTO `table`(uid,vote) VALUES('"$_POST['uid']"','1')";

mysql_query($sql);

}

echo "<script>alert('Ok 投票成功!');</script>";

echo "<script>windowlocationreload();</script>";

exit();

}else{

$sql = "SELECT `vote` FROM `table` WHERE `uid` = 3";

$result = mysql_query($sql);

if ($result && mysql_num_rows($result)) {

$t3 = mysql_fetch_assoc($result);

}else{

$t3['vote'] = 0; 

}

$sql = "SELECT `vote` FROM `table` WHERE `uid` = 4";

$result = mysql_query($sql);

if ($result && mysql_num_rows($result)) {

$t4 = mysql_fetch_assoc($result);

}else{

$t4['vote'] = 0; 

}

$sql = "SELECT `vote` FROM `table` WHERE `uid` = 5";

$result = mysql_query($sql);

if ($result && mysql_num_rows($result)) {

$t5 = mysql_fetch_assoc($result);

}else{

$t5['vote'] = 0; 

}

$sql = "SELECT `vote` FROM `table` WHERE `uid` = 6";

$result = mysql_query($sql);

if ($result && mysql_num_rows($result)) {

$t6 = mysql_fetch_assoc($result);

}else{

$t6['vote'] = 0; 

}

$sql = "SELECT `vote` FROM `table` WHERE `uid` = 7";

$result = mysql_query($sql);

if ($result && mysql_num_rows($result)) {

$t7 = mysql_fetch_assoc($result);

}else{

$t7['vote'] = 0; 

}

$count = $t3['vote']+$t4['vote']+$t5['vote']+$t6['vote']+$t7['vote'];

$t3_b = $t3['vote']/$count;

$t4_b = $t4['vote']/$count;

$t5_b = $t5['vote']/$count;

$t6_b = $t6['vote']/$count;

$t7_b = $t7['vote']/$count;

}

>

以上就是关于PHP,MYSQL制作投票系统,防止姓名、科室重复全部的内容,包括:PHP,MYSQL制作投票系统,防止姓名、科室重复、用php制作一个网页来实现简易网上投票系统、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/9827528.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-02
下一篇 2023-05-02

发表评论

登录后才能评论

评论列表(0条)

保存