Jump to content

Recommended Posts

I have this code which is a survey form that outputs information show in the code in part 2. the problem is that the total votes is not changing when i add another vote.  any suggestions?

 

<html>
<head><title> Franks Fish Market Survey</title></head>
<form action="http://69.73.144.158/~julienor/c6-e5a.php" method="post">
<font size="5" color="blue">Welcome to Franks Fish Market Survery!</font>
<br>Which seafood do you like the best?
<br>Scallops <input type="radio" name="fish" value="scallops"> 
Shrimp <input type="radio" name="fish" value="shrimp">
Oysters <input type="radio" name="fish" value="oysters">
Lobster <input type="radio" name="fish" value="lobster">
<input type="submit" onClick="getVals()" value="Pick Favorite">
<input type = "reset" value = "Reset">
</html>

 

Part 2

<html><head><title>Franks Fish Market Survey</title></head>
<body>
<font size="5" color="blue"> Survey Results </font>
<?php
$ctfile='data/survery1.txt';
$SURVEY = fopen($ctfile, 'r+') or die("Cannot open $ctfile");
flock($SURVEY, LOCK_EX) or die("Cannot lock $ctfile");
$inline = fgets($SURVEY, 4096);
list($scallops, $shrimp, $oysters, $lobster) = split(':',$inline);
if ($fish == 'scallops') {
$scallops = $scallops +1;
} elseif ($fish =='shrimp') {
$shrimp = $shrimp +1;
} elseif ($fish =='oysters') {
$oysters = $oysters +1;
} elseif ($fish =='lobster') {
$lobster = $lobster +1;
} else {}

$ct=$scallops + $shrimp + $oysters + $lobster;

$scper=($scallops/$ct)*100;
$shper=($shrimp/$ct)*100;
$oyper=($oysters/$ct)*100;
$loper=($lobster/$ct)*100;


print "<br>Scallops=$scallops (".$scper."%) Shrimp=$shrimp (".$shper."%) 
Oysters=$oysters (".$oyper."%) Lobster=$lobster (".$loper."%) Total votes=$ct";
rewind ($SURVEY);
$ret= fputs($SURVEY, "$scallops:$shrimp:$oysters:$lobster");
fclose ($SURVEY);

?></body></html>

Link to comment
https://forums.phpfreaks.com/topic/98431-need-help-fast/
Share on other sites

that worked- thanks. now i have another question

 

I have a whole bunch of code and everything works the way i want.  however, when i copy and paste the information in the address bar into a new browser, it displays text and i would rather have it go back to the first page of the code.  is it possible to add and else statement in or something like that?

Link to comment
https://forums.phpfreaks.com/topic/98431-need-help-fast/#findComment-503722
Share on other sites

On the first page, start a session and store a session variable equal to PAGE1.  As each page loads, check to see if this variable lists the previous page (if it doesn't, then they went directly to the page).  The variable is correctly set, then process the page as appropriate and change this variable to the current page.

 

When the next page loads, go through the same check sequence.  Anytime they attempt to load index6.php and the variable is NOT set to PAGE5, then use the header function to redirect them to the first page.

Link to comment
https://forums.phpfreaks.com/topic/98431-need-help-fast/#findComment-503784
Share on other sites

Just to save you the headache, use of header() has to occur prior to any other output. Usually, that's not the case so you should start the TOP of your page with:

<?php ob_start() ?>

So your output is in an output buffer, and if you use

<?php header( Location: 'http://www.example.com' ); ?>

It is automatically sent first by the output buffer because you started with ob_start();

Link to comment
https://forums.phpfreaks.com/topic/98431-need-help-fast/#findComment-503791
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.