"PHP" Voting system administrator part to increase voting and delete votes

Source: Internet
Author: User
Tags bit set
"PHP" Voting system Administrator section to increase voting and delete votes

About the voting system how about what kind of introduction is not to say that this is not graduation design

Basically say the use of PHP to implement the voting system, like other ordinary systems, divided into two parts, one is the administrator part, one is the general user part

The management part of the voting system is very simple, providing two parts of the function, increasing voting and deleting votes

The key is to design a database table,

Proposed to save a poll in this way, voteparent the title of the poll, whether the description was deleted, Votechildren the voting sub-option and the number of votes in the table.


I. BASIC OBJECTIVES

The first voting system is this:


Three links, click to be able to directly carry out the relevant functions of the operation, the main write the Administrator section, the general user part of the use of jpgraph another chapter to explain

The middle is supposed to have a login system, here is not the point, you can refer to my previous "PHP" login system and output browser information (click to open the link)

Click to open the Add voting option, will be the following interface, can be added with the delete voting option, up to 10 voting options, at least 2 avatar options, over with insufficient will prompt:


The preview is using IE6, so the add and delete options react more slowly,

After the administrator fills out the voting information, it can successfully add votes,


The administrator will be asked to add, prevent misoperation before committing

In fact, the system should also use Xajax to investigate whether there are any of the voting data, and any one option is empty should not let add, is,

For details, please refer to the "PHP" registration system and the use of Xajax Instant Verification user name is occupied (click to open the link), here did not do, because this article mainly about the voting system core implementation, here do not deduct these small details.


Then click on the voting system to delete the voting part,


At the end of each poll there is a delete button,

Click on each poll title to view this poll:


Click the Delete button will also have a query, then, click Cancel Nothing will happen, click OK to successfully delete the vote:


There are 4 votes before deletion and then only one vote after deletion.


Second, the basic idea

The administrator section of the voting system has no new technology or database operations,

First, the structure of the Voteparent table is as follows:


ID is the self-increment column, title is the big title of this vote, such as the above "I handsome not handsome" and so on, after the text used to store the description of the vote, the unfinished do not make the self-increment column, with the deletion of votes can be checked, the use of the way to delete, set the deletion bit Isdel, rendered, This is the deletion of the 0-bit poll.

The Votechildren table is as follows, the ID is the self-increment column, text is used to hold the description of each sub-option, count is used to hold the number of votes for the optional item, and ParentID is the one to which the sub-option belongs. Although it is obvious that there is a referential constraint with the Voteparent table, there is no need to set the foreign key, lest the operation be troublesome


It should be noted that after the establishment of two tables, remember to turn to the Table Options tab, the two table encoding is set to Utf-8, to avoid garbled



The directory structure of the site is as follows:


This article only describes the contents of the Createvote.html,createvote.php,delvote.php,delvotehandle.php,index.html five page


Third, the production process

1, index.html

The first is the most basic, with only three linked index.html,

Here is not to say, only three a tag, just learn HTML people will, the code is as follows:

 
  Voting systemAdd a poll (admin section)
Delete Poll (admin section)
Voting (general user section)

2, createvote.html

Add a poll page, the entire Add Voting page processing two own JS function button outside, is a large form,

There is also a hidden field to record how many options are now available,

Add a Poll action page for the next step createvote.php provides operational fundamentals

The following is a basic explanation, JavaScript operation on the Web node, you can refer to my previous "JavaScript" page node additions and deletions of the article (click to open the link)

Notice that the added sub-options node will be very regular to opt1,opt2,opt3 ... It is arranged in such a way as to facilitate the following operations

 
  Create a poll

Increase voting

Add Options Delete option Return

3, createvote.php

Add a vote processing page,

Insert the database here to note, first insert voteparent, and then find the ID of the record that just inserted voteparent, insert the parentid of the Votechildren table,

Find ParentID here. You need to be careful not to find parentid by looking for the last method to insert records, because this can cause confusion if multiple administrators are working on the concurrency of the database

Since there is Chinese,

Before you manipulate the database, remember to add mysql_query ("Set names UTF8"); In this sentence, see the code for details:

 
    adding voting processing
 ...  !--? php//First remove the title and text you want to add to the poll, the number of options in the hidden field $ptitle=$_request["title"]; $ptext =$_request["text"]; $nodetotal =$_ request["Nodetotal"]; $con =mysql_connect ("localhost", "root", "root");//Connect database if (! $con) {die ("Connection failed! ");} mysql_select_db ("Test", $con); mysql_query ("Set names UTF8");//insert title and text into the Voteparent table, set the delete bit to 0, the system will automatically generate Idmysql_ Query ("INSERT into voteparent (Title,text,isdel) VALUES (& #39;". $ptitle. " & #39;, & #39; ". $ptext." & #39;, 0); "); /again through the title to find the system-generated id$pid, $result =mysql_query ("SELECT ID as PID from voteparent where title=& #39;". $ptitle. " & #39;; "); while ($row =mysql_fetch_array ($result)) {$pid = $row ["pid"];} Set up a PHP array with each sub-option $optarr=array ();//The number of options determines our loop count for ($i =1; $i $nodetotal +1; $i + +) {$optarr [$i]=$_request[] Opt${i} "];mysql_query (" INSERT into Votechildren (Text,count,parentid) VALUES (& #39; ". $optarr [$i]." & #39;, 0,& #39; ". $pid." & #39;); ");}; Mysql_close ($con);? -->

Above, the administrator adds the voting function to finish, below is the administrator to delete the voting function


4, delvote.php

First, all the deletions in voteparent are not 1 votes, and then sorted in descending order, because people want to see the newly added polls first.

When you build the node, set the Delete button ID for each poll, which is the ID of the voteparent in the database for easy follow-up operation.

The script to delete the button does not have to write anything, that is, to upload this ID to delvotehandle.php, delete the processing page.

 
  Delete a poll

Delete a poll

Delete "; $i + +;} Mysql_close ($con);? >

Return

The basic idea is this, where this page uses the div layout, not the table, the details can refer to my previous "CSS" about div alignment and page layout (click to open the link)


5, delvotehandle.php

Take the ID just passed over, according to the ID of the corresponding Isdel delete bit set to 1

 
  Delete in voting processing ...
 
  

The above is the voting system Administrator section, increase voting and delete voting process, supposedly related to the processing page, also need to do session protection,

Avoid directly entering URLs to be accessible, not written here

Please refer to my previous "PHP" login system and output browser information (click to open the link)

  • 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.