php調查系統1

<?php
//程序名 recordvotepoll.php3
//作者:phpstudent
//本程序用於記錄投票數
//接口參數 $vpollid調查ID,$vchioceid選項ID,在提交表單中必須有著兩個參數,一般$vpollid

require(database.php3); //DATABASE.PHP3是屏蔽瞭MYSQL及ORACLE差異性的自定義數據庫接口

$db = new database();
$db->openDefaultConnection();

$SQL = “SELECT chiocenum from pollchioce where pollid=”.$vpollid.” and chioceid = “.$vchioceid;
$db->openResultset($SQL);
$db->rstNext();
$vpolldata=$db->getItem(1);
$vpolldata++; //增加票數
//更新數據表
$SQL = “update pollchioce set chiocenum = “.$vpolldata.” where
pollid=”.$vpollid.” and chioceid = “.$vchioceid;
$db->executeUpdate($SQL);
$db->executeUpdate(“COMMIT”);

$db->closeConnection();
echo(“
感謝您參與本次調查
以下是調查結果
“);
include(showresult.php3); //showresult.php3是顯示結果的文件

?>

數據表的結構如下:
1、
CREATE TABLE poll (
pollid tinyint(1) DEFAULT 0 NOT NULL,

polltitle varchar(40) NOT NULL,
polldetail varchar(200) NOT NULL,
PRIMARY KEY (pollid),
UNIQUE pollid (pollid)
);
2、
CREATE TABLE pollchioce (
pollid tinyint(1) DEFAULT 0 NOT NULL,
chioceid tinyint(1) DEFAULT 0 NOT NULL,
chiocename varchar(20) NOT NULL,
chiocenum int(5) DEFAULT 0 NOT NULL,
chiocecolor varchar(6) NOT NULL
);

You May Also Like