Current location: Hot Scripts Forums » Programming Languages » PHP » Can't get survey results from list menu


Can't get survey results from list menu

Reply
  #1 (permalink)  
Old 03-18-07, 09:07 PM
gizelle gizelle is offline
Newbie Coder
 
Join Date: Feb 2007
Location: Wisconsin
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Question Can't get survey results from list menu

Is it even possible to create a .txt document from a survey that includes list options? Here are my files:
html Code:
    <title>Airline Survey</title> <style type="text/css"> <!-- body {     background-color: #FFFFCC; } --> </style></head> <body> <h2>How Was Your Flight?</h2> <form action="TakeSurvey.php" method="get" enctype="application/x-www-form-urlencoded" name="AirlineSurvey" id="AirlineSurvey"> <p>Today's Date <input type="text" name="date" /></p> <p>Flight Number <input type="text" name="flight" /></p> <p>Departure Time <input type="text" name="time" /></p> <p> <table width="710" border="0" cellspacing="2" cellpadding="2">   <tr>     <td width="359">       <strong>Friendliness of customer staff?       </label>       </strong></td>     <td width="337"><strong>      Cleanliness of aircraft? </strong></td>   </tr>   <tr>     <td>       <select name="friendliness" size="2" id="friendliness">         <option value="Excellent">Excellent</option>         <option value="Good">Good</option>         <option value="Fair">Fair</option>         <option value="No_Opinion">No Opinion</option>         <option value="Poor">Poor</option>       </select>  </td>     <td>       <select name="cleanliness" size="2" id="cleanliness">         <option value="Excellent">Excellent</option>         <option value="Good">Good</option>         <option value="Fair">Fair</option>         <option value="No Opinion">No Opinion</option>         <option value="Poor">Poor</option>       </select>   </td>   </tr>   <tr>     <td>&nbsp;</td>     <td>&nbsp;</td>   </tr>   <tr>     <td> <strong>Space for luggage storage? </strong></td>     <td>      <strong>Noise level of aircraft? </strong></td>   </tr>   <tr>     <td>       <select name="space" size="2" id="space">         <option value="Excellent">Excellent</option>         <option value="Good">Good</option>         <option value="Fair">Fair</option>         <option value="No Opinion">No Opinion</option>         <option value="Poor">Poor</option>       </select>  </td>     <td>       <select name="noise" size="2" id="noise">         <option value="Excellent">Excellent</option>         <option value="Good">Good</option>         <option value="Fair">Fair</option>         <option value="No Opinion">No Opinion</option>         <option value="Poor">Poor</option>       </select></td>   </tr>   <tr>     <td>&nbsp;</td>     <td>&nbsp;</td>   </tr>   <tr>     <td>       <strong>Comfort of seating?       </label>       </strong></td>     <td>&nbsp;</td>   </tr>   <tr>     <td>       <select name="comfort" size="2" id="comfort">         <option value="Excellent">Excellent</option>         <option value="Good">Good</option>         <option value="Fair">Fair</option>         <option value="No Opinion">No Opinion</option>         <option value="Poor">Poor</option>       </select>   </td>     <td>&nbsp;</td>   </tr>   <tr>     <td>&nbsp;</td>     <td>&nbsp;</td>   </tr>   <tr>     <td><input type="submit" name="Submit" value="Submit" /></td>     <td><input name="Reset" type="reset" id="Reset" value="Reset" /></td>   </tr> </table> </form> <p><a href="ShowSurvey.php"><strong>View Past Survey Results</strong></a></p> </body>

My first PHP document:
php Code:
  1. <title>Survey Form</title>
  2. </head>
  3.  
  4. <body>
  5. <?php
  6. if (empty($_GET&#91;'date']) || empty($_GET['flight']) || empty($_GET['time']))
  7.     echo "<p>You must enter the date, flight number and departure time! Click your browser's Back button to return to the RSVP form. </p>";
  8. else {
  9.     $Date=addslashes($_GET&#91;'date']);
  10.     $FlightNumber=addslashes($_GET&#91;'flight']);
  11.     $DepartureTime=addslashes($_GET&#91;'flight']);
  12.     $Friendliness= ($_GET&#91;'friendliness']);
  13.     $Space =($_GET&#91;'space']);
  14.     $Comfort= ($_GET&#91;'comfort']);
  15.     $Noise= ($_GET&#91;'noise']);
  16.     $Survey=fopen("survey.txt", "a");
  17.     if (is_writable("survey.txt")) {
  18.         if (fwrite($Survey, $Date . "," . $FlightNumber . "," . $DepartureTime . "\r\n"))
  19.             echo "<p>Thank you for completing our survey!</p>";
  20.         else
  21.             echo "<p>Cannot add your information to the survey. </p>";
  22.     }
  23.         else
  24.             echo "<p>Cannot write to the file.</p>";
  25.     fclose($Survey);
  26. }
  27. ?>
  28. </body>

And my show survey results php:
php Code:
  1. <title>Show Survey</title>
  2. </head>
  3.  
  4. <body>
  5. <?php
  6.  
  7. if (is_readable("survey.txt")) {
  8.     echo "<p>The following are results from past surveys:</p><pre>";
  9.     readfile("survey.txt");
  10.     echo "</pre>";
  11. }
  12. else
  13.     echo "<p>The Surveys cannot be read.</p>";
  14.  
  15.  
  16. ?>
  17. <hr /><p><a href="AirlineSurvey.html">Return to Survey Page</a></p>
  18. </body>

This is my first semester in PHP and the &*$%$ book doesn't mention how to get results when you use list/menu in your form (which they required for this assignment)

The text box entries show up just fine .

Thanks for any assistance,
Gizelle
Reply With Quote
  #2 (permalink)  
Old 03-29-07, 09:59 PM
tomasgtz tomasgtz is offline
Newbie Coder
 
Join Date: Mar 2007
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Dear Gizelle

when a select input is received by php ONLY contains all data that user has selected, i mean

<SELECT name="ex[]">
<OPTION>op1</OPTION>
<OPTION>op2</OPTION>
<OPTION>op3</OPTION>
</SELECT>

if user selects op1 and op2 you

you can print every option selected using this

foreach($_GET["ex"] as $key => $value)
echo $value;

is very common use phpinfo();
to view what data is sent by user
__________________
Best regards,
See the best CMS http://www.publicante.com

Tomas Gutierrez
Reply With Quote
  #3 (permalink)  
Old 03-30-07, 01:12 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Your "Airline Survey" looks fine but your "Survey Form" could use a little work.

I don't know why you want to use the GET method but this should work the way you want.

I even put the results in a neat table layout.

PHP Code:

<html>
<head>
<title>Survey Form</title>
</head>
<body>
<?php
if(empty($_GET["date"]) || empty($_GET["flight"]) || empty($_GET["time"]))
{
 echo(
"<p>You must enter the date, flight number and departure time! Click your browser's Back button to return to the RSVP form.</p>");
 }
else
{
 
$Date=$_GET["date"];
 
$FlightNumber=$_GET["flight"];
 
$DepartureTime=$_GET["time"];
 
$Friendliness=$_GET["friendliness"];
 
$Cleanliness=$_GET["cleanliness"];
 
$Space=$_GET["space"];
 
$Noise=$_GET["noise"];
 
$Comfort=$_GET["comfort"];
 
 
// Enable this section if survey.txt does not exist yet. //
 /*
 if(!$Survey=fopen("survey.txt", "r"))
 {
  $Survey=fopen("survey.txt", "w");
  fclose($Survey);
  }
 */

 
if (is_writable("survey.txt"))
 {
  
$Survey=fopen("survey.txt""a");
  
fwrite($Survey$Date."\r\n");
  
fwrite($Survey$FlightNumber."\r\n");
  
fwrite($Survey$DepartureTime."\r\n");
  
fwrite($Survey$Friendliness."\r\n");
  
fwrite($Survey$Cleanliness."\r\n");
  
fwrite($Survey$Space."\r\n");
  
fwrite($Survey$Noise."\r\n");
  
fwrite($Survey$Comfort."\r\n");
  
fclose($Survey);
  echo 
"<p>Thank you for completing our survey!</p>";
  }
 else
 {
  echo 
"<p>Cannot add your information to the survey. </p>";
  echo 
"<p>Cannot write to the file.</p>";
  }
 }
?>
</body>
</html>
And your show survey results php:
PHP Code:

<html>
<head>
<title>Show Survey</title>
</head>
<body>
<?php
if (is_readable("survey.txt"))
{
 
$a=fopen("survey.txt""r");
 echo(
"<table style=\"border:1px solid #000000;width:100%\" rules=\"all\">");
  echo(
"<tr>");
   echo(
"<td colspan=8 style=\"text-align:center;\">");
    echo 
"<span style=\"font-size:32px;font-weight:bold;\">The following are results from past surveys:</span>";
   echo(
"</td>");
  echo(
"</tr>");
  echo(
"<tr>");
   echo(
"<th>");
    echo(
"Date");
   echo(
"</th>");
   echo(
"<th>");
    echo(
"Flight");
   echo(
"</th>");
   echo(
"<th>");
    echo(
"Time");
   echo(
"</th>");
   echo(
"<th>");
    echo(
"Friendlyness");
   echo(
"</th>");
   echo(
"<th>");
    echo(
"Cleanliness");
   echo(
"</th>");
   echo(
"<th>");
    echo(
"Space");
   echo(
"</th>");
   echo(
"<th>");
    echo(
"Noise");
   echo(
"</th>");
   echo(
"<th>");
    echo(
"Comfort");
   echo(
"</th>");
  echo(
"</tr>");
  while(!
feof($a))
  {
   echo(
"<tr>");
   echo(
"<td>");
    echo(
"<pre>".trim(fgets($a))."</pre>");
   echo(
"</td>");
   echo(
"<td>");
    echo(
"<pre>".trim(fgets($a))."</pre>");
   echo(
"</td>");
   echo(
"<td>");
    echo(
"<pre>".trim(fgets($a))."</pre>");
   echo(
"</td>");
   echo(
"<td>");
    echo(
"<pre>".trim(fgets($a))."</pre>");
   echo(
"</td>");
   echo(
"<td>");
    echo(
"<pre>".trim(fgets($a))."</pre>");
   echo(
"</td>");
   echo(
"<td>");
    echo(
"<pre>".trim(fgets($a))."</pre>");
   echo(
"</td>");
   echo(
"<td>");
    echo(
"<pre>".trim(fgets($a))."</pre>");
   echo(
"</td>");
   echo(
"<td>");
    echo(
"<pre>".trim(fgets($a))."</pre>");
   echo(
"</td>");
  echo(
"</tr>");
  }
 echo(
"</table>");
 
fclose($a);
 }
else
{
 echo(
"<p>The Surveys cannot be read.</p>");
 echo(
"<hr>");
 echo(
"<p>");
 echo(
"<a href=\"AirlineSurvey.html\">Return to Survey Page</a>");
 echo(
"</p>");
 }
?>
</body>
</html>
__________________
Jerry Broughton

Last edited by job0107; 03-30-07 at 01:14 AM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Create dropdown menu from comma separated list of numbers maya77 PHP 22 03-20-11 11:35 AM
trouble with the display of results and drop down list.. SummerL PHP 0 07-11-05 10:38 AM
Xml / Dom / Css Mark_SC.SE JavaScript 0 06-29-05 08:05 AM


All times are GMT -5. The time now is 05:58 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.