展开全部
PHP:<?php
header('Content-Type:text/html;charset=utf-8');
mysql_connect("localhost","root","")ordie('Thedatabaseconnectionfailed');
mysql_select_db("vote")ordie('Thedatabaseiswrongchoice');
mysql_query('SETNAMESUTF8');
if(isset($_POST['name']))
{
@mysql_query("UPDATE`list`SET`votes`=(SELECT`votes`FROM(SELECT*FROMlist)asbWHERE`id`={$_POST['name']})+1WHERE`id`={$_POST['name']}");
$result=@mysql_query("SELECT*FROM`list`");
echo"当前票数:";
while($query=mysql_fetch_array($result,MYSQL_ASSOC))
{
echo$query['name'].":{$query['votes']}
";
}
echo"返回上页";
}
else
{
$result=@mysql_query("SELECT*FROM`list`");
echo'
';
echo"谁最聪明32313133353236313431303231363533e58685e5aeb931333337393031:";
while($query=mysql_fetch_array($result,MYSQL_ASSOC))
{
echo"".$query['name'];
}
echo'';
echo'
';
}
?>
mysql:SETSQL_MODE="NO_AUTO_VALUE_ON_ZERO";
CREATEDATABASE`vote`DEFAULTCHARACTERSETutf8COLLATEutf8_general_ci;
USE`vote`;
CREATETABLE`list`(
`id`int(11)NOTNULLauto_increment,
`name`varchar(20)NOTNULL,
`votes`int(11)NOTNULL,
PRIMARYKEY(`id`)
)ENGINE=MyISAMDEFAULTCHARSET=utf8AUTO_INCREMENT=3;
INSERTINTO`list`VALUES(1,'小明',0);
INSERTINTO`list`VALUES(2,'小文',0);
我觉得也够简单了