search
Homephp教程php手册php 投票(调查)

php 投票(调查)

Jun 13, 2016 am 10:47 AM
includephpvoteinvestigation

/**
 * 投票调查
 * 
 * 
 * */ 
include "isLogin.php"; 
include "../conn/config.inc.php"; 
/*action操作初始化*/ 
if(emptyempty($_REQUEST['action'])){ 
    $_REQUEST['action']='list'; 
}else { 
    $_REQUEST['action']=trim($_REQUEST['action']); 

 
if($_REQUEST['action']=='add'){ 
    $tpl->assign('submitButton','添加'); 
    $tpl->assign('tmess','添加投票选项'); 
    $tpl->assign('act','insert'); 
    $tpl->display('admin/addpoll.tpl'); 
}elseif ($_REQUEST['action']=='insert'){ 
    $title=$_POST['title']; 
    $desc=$_POST['desc']; 
    $addtime=time(); 
    $poll=$_POST['poll']; 
 
    $sql="insert into  poll (title,des,addtime) values ('$title','$desc','$addtime')"; 
    $rs=$db->query($sql); 
    $lastid=$db->insert_id(); 
 
   foreach ($poll as $v){ 
   $sql2="insert into poll_option (pollid,opdata) values ('$lastid','$v')"; 
   $rs2=$db->query($sql2); 
     } 
    if($rs&&$rs2){ 
        echo "<script>location.href=&#39;poll.php?action=polllist&#39;</script>"; 
    }else{ 
        echo "<script>alert(&#39;失败!&#39;);history.go(-1)</script>"; 
    } 

//投票列表 
elseif ($_REQUEST['action']=='polllist'){ 
//  $sql="select * from poll order by id desc"; 
//  $rs=$db->query($sql); 
//  $poll=$db->fetch_array($rs); 
    $poll=getpoll(); 
    $tpl->assign('poll',$poll); 
    $tpl->assign('tmess','投票列表'); 
    $tpl->display('admin/polllist.tpl'); 

//删除 
elseif ($_REQUEST['action']=='del'){ 
    $id=$_GET['id']; 
     $sql="delete from poll where id={$id}"; 
     $sql2="delete from poll_option where pollid={$id}"; 
//echo  $sql="delete from poll INNER JOIN poll_option ON poll_option.pollid=poll.id where id={$id}"; 
    $rs=$db->query($sql); 
    $rs2=$db->query($sql2); 
    if($rs&&$rs2){ 
        echo "<script>location.href=&#39;poll.php?action=polllist&#39;</script>"; 
    }else{ 
        echo "<script>alert(&#39;失败!&#39;);history.go(-1)</script>"; 
    } 

elseif ($_REQUEST['action']=='edit'){ 
    $id=intval($_GET['id']); 
//  $sql="SELECT p.id, p.title, p.des, p.addtime, po.id, po.pollid, po.opdata 
//         FROM poll AS p 
//         LEFT JOIN poll_option AS po ON p.id = po.pollid 
//         WHERE p.id ={$id}"; 
    $sql="select * from poll where id={$id}"; 
    $rs=$db->query($sql); 
    $row=$db->fetch_array($rs); 
    $sql2="select* from poll_option where pollid={$id} order by id ASC"; 
    $rs2=$db->query($sql2); 
    $i=0; 
    $potion=''; 
    while ($row2=$db->fetch_array($rs2)){ 
        $i++; 
        $potion.="

"; 
        if($i>2){ 
        $potion.=""; 
        } 
        $potion.="
"; 
    } 
    $tpl->assign('pp',$potion); 
    $tpl->assign('post',$row); 
    $tpl->assign('tmess','更新投票'); 
    $tpl->assign('submitButton','更新'); 
    $tpl->assign('act','update'); 
    $tpl->display('admin/editpoll.tpl'); 

//更新投票信息  www.2cto.com
elseif ($_REQUEST['action']=='update'){ 
     
    $id=$_POST['id']; 
    $title=$_POST['title']; 
    $desc=$_POST['desc']; 
    $addtime=time(); 
    $poll=$_POST['poll']; 
    $sql="update poll SET title='{$title}',des='{$desc}',addtime='{$addtime}' where id='{$id}'"; 
    $rs=$db->query($sql); 
    foreach ($poll as $k=> $v){ 
//      echo "ID:是".$k."值是:".$v; 
//      echo "
"; 
        $sql2="update poll_option SET opdata='{$v}' where id='{$k}' and pollid={$id} "; 
        $rs2=$db->query($sql2); 
    } 
    if($rs&&$rs2){ 
        echo "<script>location.href=&#39;poll.php?action=polllist&#39;</script>"; 
    }else{ 
        echo "<script>alert(&#39;更新失败!&#39;);history.go(-1)</script>"; 
    } 

 
 
 
 
//==============投票相关函数================= 
//获取投票信息 
function  getpoll(){ 
    global $db; 
    $sql="select * from poll order by id desc"; 
    $rs=$db->query($sql); 
    $data=array(); 
    while ($row=$db->fetch_array($rs)){ 
        $data[]=$row; 
    } 
    return $data; 
}
 
?> 

摘自 chaojie2009的专栏
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software