Php voting (investigation) _ PHP Tutorial

Source: Internet
Author: User
Php voting (investigation ).? Php *** voting survey *** includeisLogin. php; include .. connconfig. inc. php; * action operation initialization * if (emptyempty ($ _ REQUEST [action]) {$ _ REQUEST [action] list;} else {$ _ /**
* 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

Http://www.bkjia.com/PHPjc/478383.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/478383.htmlTechArticle? Php/*** voting survey ***/include isLogin. php; include .. /conn/config. inc. php;/* action operation initialization */if (emptyempty ($ _ REQUEST [action]) {$ _ REQUEST [action] = list;} else {$ _...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.