Home  >  Article  >  Backend Development  >  Online survey and voting system written in PHP_PHP tutorial

Online survey and voting system written in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:05:49882browse

This is a simple voting program, which is a good introductory program for friends who are just learning PHP. Here I will introduce it to you, I hope it will be helpful to my friends.

The system is composed of the following four files: survey.htm with HTML survey form, survey.php that implements the survey function, data.txt that records survey items, and survey.txt that records survey results. Among them, data.txt and survey.txt can be created respectively using NOTEPAD and transferred to the program directory. The file data.txt stores the items to be investigated. Note that each item should occupy one line; survey.txt can be an empty file with no content.

The code of Survey.htm can be as follows:



survey
< ;/head>


Survey item one


Survey item two

Survey item three


Survey item four


Survey item Five




View results




Note that the survey items in the file data.txt and the survey items above must be consistent in number and order, otherwise errors or surveys will occur The results are inaccurate. At the same time, in order to display the survey results in the form of a bar chart, several bar pictures of different colors should be prepared. Such as: 0.gif, 1.gif, 2.gif, 3.gif, 4.gif, etc.

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 file*/
$file_votes=fopen($votes, "r");
$line_votes=fgets($file_votes, 255); /*Read the recorded survey results*/
fclose($file_votes);
$single_vote=explode("|", $line_votes); /* Split the data according to the specified string, and then transfer the string back to the array variable*/
if ($result!=1) / *If you have already accepted the investigation*/
{
$file_votes=file($votes, "r");
if ($REMOTE_ADDR == $file_votes[1]) /*Check if it is the same person */
{
echo "
You have already voted, thank you for your participation!
";
exit ;
}
/*If the IP is not repeated, execute the following procedure*/


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445093.htmlTechArticleThis is a simple voting program, which is a good introductory program for friends who are just learning PHP. Here I will introduce it to you, I hope it will be helpful to my friends. The system is...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn