Php voting (investigation)
Last Update:2014-05-15
Source: Internet
Author: User
& Lt ;? Php/*** voting survey ***/include & quot; isLogin. php & quot; include & quot ;.. /conn/config. inc. php & quot;/* action operation initialization */if (emptyempty ($ _ REQUEST [& amp; #39; action & amp; #39 /**
* Voting investigation
*
*
**/
Include "isLogin. php ";
Include "../conn/config. inc. php ";
/* Initialize the action */
If (emptyempty ($ _ REQUEST ['action']) {
$ _ REQUEST ['action'] = 'list ';
} Else {
$ _ REQUEST ['action'] = trim ($ _ REQUEST ['action']);
}
If ($ _ REQUEST ['action'] = 'ADD '){
$ Tpl-> assign ('submitclick', 'ADD ');
$ Tpl-> assign ('tmess', 'Add voting options ');
$ 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 = 'poll. php? Action = polllist 'script ";
} Else {
Echo "script alert ('failed! '); History. go (-1) script ";
}
}
// Voting list
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', 'voting list ');
$ Tpl-> display ('admin/polllist. tpl ');
}
// Delete
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 = 'poll. php? Action = polllist 'script ";
} Else {
Echo "script alert ('failed! '); 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', 'update void ');
$ Tpl-> assign ('submitclick', 'update ');
$ Tpl-> assign ('Act ', 'update ');
$ Tpl-> display ('admin/editpoll. tpl ');
}
// Update the Voting information 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: Yes". $ k. "value:". $ 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 = 'poll. php? Action = polllist 'script ";
} Else {
Echo "script alert ('update failed! '); History. go (-1) script ";
}
}
// =================== Vote-related functions ============================
// Obtain the voting information
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;
}
?>
From chaojie2009