Online Survey program code

Source: Internet
Author: User
  code is as follows copy code


<title> online Survey code </title>

<body>
<form method= Post "action=" survey.php Tutorial >
  <p><input type= "Radio" value= "0" name= "vote" > Investigation Project One </p>
  <p><input type= "Radio" name= "Vote" value= "1" > Survey Items two </p>
  <p><input Type= "Radio" name= "Vote" value= "2" > Survey items three </p>
  <p><input type= "Radio" name= "Vote" value= "3 "> Research project four </p>
  <p><input type=" Radio "name=" Vote "value=" 4 "> Research project Five </p>
  & Lt;p><input type= "hidden" name= "Go"   value= "1" >
  <p><input type= "Submit" value= "submitted" Name= "B1" ></p>
  <a href= "www.111cn.net.php?result=1" > View results </a>
</form>
</body>

survey.php

?

The code is as follows Copy Code

/*
No Database Tutorials online poll survey PHP code

*/
$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, execute the following procedure * *
$ficdest =fopen ($votes, "w");
For ($i =0 $i <=count ($DATAF)-1; $i + +)
{
if ($i = = $vote)
{/* Determine which item is selected. *
$single _vote[$i]+=1;
}
Fputs ($ficdest, "$single _vote[$i]|"); /* Write data back to File/*
}
Fputs ($ficdest, "$remote _addr");///written to voters ip*/
Fclose ($ficdest);
$result = 1; * * Voted successfully * *
}

* * Write the results of the poll and show the result of the poll
if ($result ==1)
{
echo "<table cellpadding=10>";
For ($i =0 $i <=count ($DATAF)-1; $i + +)
{
* * Get Total votes
$tot _votes+= $single _vote[$i];
}
For ($i =0 $i <=count ($DATAF)-1; $i + +)
{
$imag =strval ($i). " GIF ";/* determine which bar picture to use to display statistical results. *
$stat [$i]= $single _vote[$i]/$tot _votes*100; /* percent Calculated * *
$SCLA = $stat [$i]*5;/* bar chart and magnification, here is 5 times times the width of the phase element of the Ann percentage to display. *
echo "<tr><td><li><font Face=verdana size=2>";
echo "$dataf [$i]</font></td><td align=left><font face=verdana size=2>";
echo "&nbsp;"; * Output Barcode Chart * *
printf ("%.1f", "$stat [$i]");
echo "%</font></td><td Align=center><font face=verdana size=2>";
/* Output the number of votes in this column * *
echo "$single _vote[$i]</font>";
echo "</td></tr>";
}
echo "</table><p>";
echo "<font Face=verdana size=2> Total number of votes: $tot _votes </font>";
}

/*
Data.txt file
Survey Project A
Survey Item Two
Survey Item Three
Survey Item Four
Survey Item Five
*/
?>

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.