julien Posted March 29, 2008 Share Posted March 29, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/98431-need-help-fast/ Share on other sites More sharing options...
MadTechie Posted March 29, 2008 Share Posted March 29, 2008 part 2 add list($scallops, $shrimp, $oysters, $lobster) = split(':',$inline); $fish = $_POST['fish'];//ADD this line if ($fish == 'scallops') { Quote Link to comment https://forums.phpfreaks.com/topic/98431-need-help-fast/#findComment-503718 Share on other sites More sharing options...
julien Posted March 29, 2008 Author Share Posted March 29, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/98431-need-help-fast/#findComment-503722 Share on other sites More sharing options...
MadTechie Posted March 29, 2008 Share Posted March 29, 2008 i am not 100% sure what your asking, sounds like a redirect in which case you could use header("location: http://blar"); or javascript or meta tags Quote Link to comment https://forums.phpfreaks.com/topic/98431-need-help-fast/#findComment-503724 Share on other sites More sharing options...
julien Posted March 29, 2008 Author Share Posted March 29, 2008 i think it is a re-direct. don't mean to sound stupid, but I am not sure to how apply the things you are saying into my code. Quote Link to comment https://forums.phpfreaks.com/topic/98431-need-help-fast/#findComment-503725 Share on other sites More sharing options...
doni49 Posted March 29, 2008 Share Posted March 29, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/98431-need-help-fast/#findComment-503784 Share on other sites More sharing options...
ucffool Posted March 29, 2008 Share Posted March 29, 2008 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(); Quote Link to comment https://forums.phpfreaks.com/topic/98431-need-help-fast/#findComment-503791 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.