PHP Voting system additions and deletions voting (Admin article) _php tips

Source: Internet
Author: User
Tags bit set xmlns

About the voting system how the introduction is not much to say, this is not a graduation design, mainly said that the use of PHP to implement the voting system, like other ordinary systems, divided into two parts, one is the Administrator section , one is the General user section.

About the management part of the voting system, very simple to provide a two-part function to increase voting and delete votes

The key is to design the table of the database, draw up in such a vote, voteparent the title of the vote, description is deleted, Votechildren table to save the vote of the sub-option and the number of votes

I. BASIC OBJECTIVES

The first voting system is this:


Three links, point in to directly to the operation of related functions, this article main write Administrator section, the ordinary user part of the use of jpgraph another chapter to explain

In the middle should have login system, here is not the focus, you can refer to my previous "" PHP login system and Output viewer information (click to open the link)

Click to add voting options, will be the following interface, to be able to add and delete voting options, up to 10 voting options, at least 2 avatar options, over and below will prompt:


The preview is using IE6, so the Add and remove options react slowly, and after the administrator fills out the voting information, the vote is successfully added.


Before submitting, ask the administrator if you want to add, to prevent misoperation, the system here should also use Xajax to investigate whether there are any of the voting data, and any option is empty should not be added, the details can refer to the "PHP" registration system and the use of Xajax Instant Authentication user name is occupied A text (click to open the link), not done here, because this article is mainly about voting system core implementation, here is not to buckle these small details.

Then click the voting system to delete the voting section:


At the end of each vote there is a Delete button, click on each of the voting titles to view this vote:


Click on the Delete button will also have inquiries, and then, click Cancel Nothing will happen, click to confirm the successful deletion of the vote:


It is clear from the above figure that there are 4 votes before deletion and then only one vote after deletion.

Ii. Basic Ideas

The Administrators section of the voting system has no new technology or database operations, first voteparent the table structure as follows:


ID is a self added column, title is the headline of this vote, for example, the above "I am not handsome" and so on, after the text used to store the description of the vote, unfinished do not make the column disconnected, and delete the vote can be checked, with the deletion of the way, set the deletion bit Isdel, presented, This is the deletion bit for the 0 vote.

The Votechildren table is as follows, the ID is the self added column, the text is used to hold the description of each of the options, the number of votes used to hold the item, and the vote that the ParentID uses to hold the sub option. Although it is obvious that there is a referential constraint with the Voteparent table, there is no need to set a foreign key to avoid trouble during operation.


It is worth noting that, after the establishment of two tables, remember to turn to the Table tab card, the two table encoding are set to utf-8, to avoid garbled


The directory structure of the site is as follows:


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

Third, the production process
1, index.html
first is the most basic, there are only three links index.html, here is not to say, only three a tag, just learn HTML people will be, the code is as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
 
 

  2, createvote.html
  Add a voting page, the entire add to the voting page to deal with two of its own JS function button, is a large form, There is also a hidden field that records how many options are now available,
  provides an operational basis for the next add Voting action page createvote.php.
  below for a basic description of the operation of JavaScript on the Web node, you can refer to my previous "JavaScript for Web node additions and deletions to check usage examples" (Click to open the link)
  Note that the added child options node will be very regular to opt1,opt2,opt3 ... In that order, this is to facilitate the operation of the following  

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">  

3, createvote.php
  Add voting processing page, insert database here to note that first insert voteparent, Find out the ID of the record that just inserted voteparent, insert the parentid of the Votechildren table, find parentid here, and don't find parentid by looking for the last way to insert records. Because of this, if more than one administrator is manipulating the concurrency of the database, there will be confusion because there is Chinese, before you manipulate the database, remember to add mysql_query ("Set names UTF8"); For more information, see Code:

 <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">  

  above, admin to add voting function done, the following is the administrator to delete the voting function
 4, delvote.php
First of all the voteparent delete bits are not 1 of the voting query out, and then descending order, because people want to see the latest addition of the vote, the generation of nodes set up every vote of the deletion button ID, this ID is in the database of the Voteparent ID, convenient for subsequent operations, Delete the button script does not need to write what, is to pass this ID to delvotehandle.php, deletes the processing page to be possible the

 <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">  

</script> The basic idea is this, where this page uses a div layout, rather than a table, 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 this ID the corresponding Isdel delete bit set to 1 can

 <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
 
 

The above is the voting system administrator part, increases the vote and deletes the vote the process, is supposed that the related processing page, also needs to carry on the session the protection,
To avoid direct input to the Web site can access, here is not written, you can refer to my previous "Php+mysql to achieve login system and output browser information function" (Click to open the link)

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.