An online poll system written in PHP

Source: Internet
Author: User

This is a simple voting procedure, for just learning PHP and friends is a very good starter program. Here to introduce you, hope to be able to help friends.

The system consists of the following four files: The survey.htm of the HTML survey form, the survey.php of the investigation function, and the data.txt of the investigation project. and record the results of the survey survey.txt. of which Data.txt and Survey.txt can be created separately by Notepad and uploaded to the program directory. The document Data.txt the items to be investigated, focusing on one line for each project, while Survey.txt can be an empty file with no content.

The survey.htm code can be as follows:

<title>survey</title>
<body>
<form method= "POST" action= "survey.php" >
<p><input type= "Radio" value= "0" name= "vote" > Investigation Project </p>
<p><input type= "Radio" name= "Vote" value= "1" > Survey Item two </p>
<p><input type= "Radio" name= "Vote" value= "2" > Survey Item three </p>
<p><input type= "Radio" name= "Vote" value= "3" > Survey Item four </p>
<p><input type= "Radio" name= "Vote" value= "4" > Survey Item five </p>
<p><input type= "hidden" name= "Go" value= "1" >
<p><input type= "Submit" value= "submitted" name= "B1" ></p>
<a href= "Survey.php?result=1" > View results </a>
</form>
</body>

Focus on the survey items in the document Data.txt and the above survey items in the number and order must be consistent, otherwise there will be errors or the results of the investigation is inaccurate. At the same time, in order to display the results of the survey into a bar chart, you should prepare a number of different colors of the bar picture. such as: 0.gif,1.gif,2.gif,3.gif,4.gif and so on.

The following is the survey.php code to implement the survey function:

?
$data = "Data.txt";
$votes = "Survey.txt";
$dataf =file ($data); /* Read the items in the survey project document * *
$file _votes=fopen ($votes, "R");
$line _votes=fgets ($file _votes, 255); * * read out the results of the investigation as recorded.
Fclose ($file _votes);
$single _vote=explode ("|"), $line _votes); /* and the data is cut into the specified string, then the string is passed back to the array variable.
if ($result!=1)/* If the investigation has been accepted * *
{
$file _votes=file ($votes, "R");
if ($REMOTE _addr = = $file _votes[1])/* Check is not the same person * *
{
echo "<center><font color=red> you have voted, thank you for your participation!" </font></center> ";
Exit
}
* If IP does not repeat, the following procedures are executed.

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.