Jump to content

Recommended Posts

I thought I had this cracked yesterday - but I've been staring at it for too long now and the answer's probably staring at me in the face but I can't see it! Can anyone point me in the right direction please to get this form working! Thanks

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Basic Test</title>
</head>

<body><?php


// get posted data into local variables
$EmailFrom = "basictest1@citizenet.co.uk";
$EmailTo = "esol@citizenet.co.uk";
$Subject = "Basic Test 1 Test Submission";

$fields = array('Name', 'Email',
                'B1A', 'B1B', 'B1C', 'B1D',
                'B2A', 'B2B', 'B2C', 'B2D',
                'B3A', 'B3B', 'B3C', 'B3D',
                'B4A', 'B4B', 'B4C', 'B4D',
                'B5A', 'B5B', 
                'B6A', 'B6B', 'B6C', 'B6D',
                'B7A', 'B7B', 'B7C', 'B7D'
                'B8A', 'B8B', 'B8C', 'B8D',
                'B9A', 'B9B', 'B9C', 'B9D',
                'B10A', 'B10B',
                'B11A', 'B11B', 'B11C', 'B11D',
                'B12A', 'B12B', 'B12C', 'B12D',
                'B13A', 'B13B',  'B13C', 'B13D',
                'B14A', 'B14B', 'B14C', 'B14DN',
                'B15A', 'B15B',
                'B16A', 'B16B', 'B16C', 'B16D',
                'B17A', 'B17B', 'B17C', 'B17D',
                'B18A', 'B18B', 'B18C', 'B18D',
                'B19A', 'B19B', 'B19C', 'B19D',
                'B20A', 'B20B', 
                'B21A', 'B21B', 'B21C', 'B21D',
                'B22A', 'B22B', 'B22C', 'B22D',
                'B23A', 'B23B', 'B23C', 'B23D',
                'B24A', 'B24B', 'B24C', 'B24D');
$Body = '';
foreach($fields as $field)
{
    $value = '';
    if(isset($_POST[$field]))
    {
        $value = trim(stripslashes($_POST[$field]));
    }

    $Body .= $field.": \n";
    $Body .= $_POST[$field]."\n";
}

// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=okbasic.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/121394-solved-php-form-processing-error/
Share on other sites

I hate to say it but you're not actually echo'ing anything out... so you should at least get some html source

Also, you're writing your meta refresh tag into the <body> of the html document, when it should be placed in the <head> section (that's if you want the refresh to work...)

 

Therefore, my questions are:

1) what does the resultant html source look like (you can check this using any modern browser).

2) do you want to redirect to another page on success?

3) if this page doesn't actually display anything why are you bothering to output any html at all, as there are other ways to redirect ;)

a bit longwinded but here's the htmp (published) page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Free Test</title>
<style type="text/css">
<!--
body,td,th {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
color: #000033;
}
body {
background-color: #8EC2FC;
}
-->
</style>
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
</head>

<body><form method="POST" action="basictest.php" form name="DateForm1">
  <p>:<br>



<table width="800" border="0" align="center" cellpadding="2" cellspacing="2" bgcolor="#FFFFFF">
  <tr>
    <td colspan="4"><div align="center"><img src="images/header.jpg" width="800" height="170" /></div></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center">This is a basic test based on the questions asked in the 'Life in the UK' Test. You have 45 minutes to complete the test.<br />
      Click 'Start' to activate the timer<br />
          <script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','225','height','120','src','timer','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','timer' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="225" height="120">
            <param name="movie" value="timer.swf" />
            <param name="quality" value="high" />
            <embed src="timer.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="225" height="120"></embed>
          </object>
          </noscript><br />
        <br />
    </div></td>
    </tr>
  <tr>
    <td width="8"> </td>
    <td width="386"><div align="left">Your Name: 
      <input name="Name" type="text" size="40" />
    </div></td>
    <td width="387"><div align="right">Your Email:
      <input name="Email" type="text" size="40" />
    </div></td>
    <td width="1"> </td>
    </tr>
  <tr>
    <td colspan="4"><hr />      <div align="center"><strong>1. Which of these is an illegal drug (this means it should not be used)?</strong></div></td>
    </tr>
  
  <tr>
    <td> </td>
    <td><div align="left">A.      Paracetamol
        <input type="checkbox" name="B1A" value="Yes" />
    </div></td>
    <td>B.
Ibuprofen 
      <input type="checkbox" name="B1B" value="Yes" /></td>
    <td> </td>
    </tr>
  <tr>
    <td> </td>
    <td>C. Heroin
      <input type="checkbox" name="B1C" value="Yes" /></td>
    <td>D. Prozac
      <input type="checkbox" name="B1D" value="Yes" /></td>
    <td> </td>
    </tr>
  <tr>
    <td colspan="4"><hr /></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center"><strong>2. Boxing day is:</strong></div></td>
    </tr>
  <tr>
    <td> </td>
    <td>A. 24th December 
      
      <input type="checkbox" name="B2A" value="Yes" />      </td>
    <td>B. 25th December <input type="checkbox" name="B2B" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td>C. 26th December <input type="checkbox" name="B2C" value="Yes" /></td>
    <td>D. 1st January <input type="checkbox" name="B2D" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="4"><hr /></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center"><strong>3. Which religion celebrates EID?</strong></div></td>
    </tr>
  <tr>
    <td> </td>
    <td>A. Roman Catholic <input type="checkbox" name="B3A" value="Yes" /></td>
    <td>B. Hindu <input type="checkbox" name="B3B" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td>C. Moslem <input type="checkbox" name="B3C" value="Yes" /></td>
    <td>D. Jewish <input type="checkbox" name="B3D" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="4"><hr /></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center"><strong>4. Valentine's Day is:</strong></div></td>
    </tr>
  <tr>
    <td> </td>
    <td>A. 14th February <input type="checkbox" name="B4A" value="Yes" /></td>
    <td>B. 14th March <input type="checkbox" name="B4B" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td>C. 1st April <input type="checkbox" name="B4C" value="Yes" /></td>
    <td>D. 23rd April <input type="checkbox" name="B4D" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="4"><hr /></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center"><strong>5. If you have a provisional driving licence you can drive a car on your own</strong></div></td>
    </tr>
  <tr>
    <td> </td>
    <td>A. True <input type="checkbox" name="B5A" value="Yes" /></td>
    <td>B. False <input type="checkbox" name="B5B" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="4"><hr /></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center"><strong>6. The most popular and traditional meat at Christmas is:</strong></div></td>
    </tr>
  <tr>
    <td> </td>
    <td>A. Beef <input type="checkbox" name="B6A" value="Yes" /></td>
    <td>B. Lamb <input type="checkbox" name="B6B" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td>C. Chicken <input type="checkbox" name="B6C" value="Yes" /></td>
    <td>D. Turkey <input type="checkbox" name="B6D" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="4"><hr /></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center"><strong>7. In G.C.S.E exams, the letters G.C.S.E. mean:</strong></div></td>
    </tr>
  <tr>
    <td> </td>
    <td>A. General Cerificate of Standard Education <input type="checkbox" name="B7A" value="Yes" /></td>
    <td>B. General Certificate of Secondary Education <input type="checkbox" name="	B7A" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td>C. General Cerificate of Simple Education <input type="checkbox" name="B7C" value="Yes" /></td>
    <td>D. Government Certificate of Secondary Education <input type="checkbox" name="B7D" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="4"><hr /></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center"><strong>8. In 'A' level exams, the letter 'A' stands for:</strong></div></td>
    </tr>
  <tr>
    <td> </td>
    <td>A. Advanced <input type="checkbox" name="B8A" value="Yes" /></td>
    <td>B. Attainment <input type="checkbox" name="B8B" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td>C. Actual <input type="checkbox" name="B8C" value="Yes" /></td>
    <td>D. Nothing <input type="checkbox" name="B8D" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="4"><hr /></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center"><strong>9. The political party in power in 2008:</strong></div></td>
    </tr>
  <tr>
    <td> </td>
    <td>A. Conservative <input type="checkbox" name="B9A" value="Yes" /></td>
    <td>B. Green Party <input type="checkbox" name="B9B" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td>C. Liberal Democrat <input type="checkbox" name="B9C" value="Yes" /></td>
    <td>D. Labour <input type="checkbox" name="B9D" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="4"><hr /></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center"><strong>10. In the UK, smoking is allowed anywhere:</strong></div></td>
    </tr>
  <tr>
    <td> </td>
    <td>A. True <input type="checkbox" name="B10A" value="Yes" /></td>
    <td>B. False <input type="checkbox" name="B10B" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="4"><hr /></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center"><strong>11. When was the First World War?</strong></div></td>
    </tr>
  <tr>
    <td> </td>
    <td>A. 1814 - 1818 <input type="checkbox" name="B11A" value="Yes" /></td>
    <td>B. 1914 - 1918 <input type="checkbox" name="B11B" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td>C. 1939 - 1945 <input type="checkbox" name="B11C" value="Yes" /></td>
    <td>D. 1904 - 1910 <input type="checkbox" name="B11D" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="4"><hr /></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center"><strong>12. Children can have a part-time job at the age of:</strong></div></td>
    </tr>
  <tr>
    <td> </td>
    <td>A. 12 Years <input type="checkbox" name="B12A" value="Yes" /></td>
    <td>B. 13 Years <input type="checkbox" name="B12B" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td>C. 14 Years <input type="checkbox" name="B12C" value="Yes" /></td>
    <td>D. At any age <input type="checkbox" name="B12D" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="4"><hr /></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center"><strong>13. When was the Second World War?</strong></div></td>
    </tr>
  <tr>
    <td> </td>
    <td>A. 1840 - 1846 <input type="checkbox" name="B13A" value="Yes" /></td>
    <td>B. 1900 - 1905 <input type="checkbox" name="B13B" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td>C. 1914 - 1918 
      <input type="checkbox" name="B13C" value="Yes" /></td>
    <td>D. 1939 - 1945 <input type="checkbox" name="B13D" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="4"><hr /></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center"><strong>14. Young people cannot buy alcohol until they are:</strong></div></td>
    </tr>
  <tr>
    <td> </td>
    <td>A. 16 Years <input type="checkbox" name="B14A" value="Yes" /></td>
    <td>B. 17 Years <input type="checkbox" name="B14B" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td>C. 18 Years <input type="checkbox" name="B14C" value="Yes" /></td>
    <td>D. 21 Years <input type="checkbox" name="B14D" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="4"><hr /></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center"><strong>15. Scottish speak only Scottish:</strong></div></td>
    </tr>
  <tr>
    <td> </td>
    <td>A. True <input type="checkbox" name="B15A" value="Yes" /></td>
    <td>B. False <input type="checkbox" name="B15B" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="4"><hr /></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center"><strong>16. In the UK there is a Census every:</strong></div></td>
    </tr>
  <tr>
    <td> </td>
    <td>A. Year <input type="checkbox" name="B16A" value="Yes" /></td>
    <td>B. 5 Years <input type="checkbox" name="B16B" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td>C. 10 Years <input type="checkbox" name="B16C" value="Yes" /></td>
    <td>D. 100 Years <input type="checkbox" name="B16D" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="4"><hr /></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center"><strong>17. The next Census will be held in:</strong></div></td>
    </tr>
  <tr>
    <td> </td>
    <td>A. 2009 <input type="checkbox" name="B17A" value="Yes" /></td>
    <td>B. 2010 <input type="checkbox" name="B17B" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td>C. 2011 <input type="checkbox" name="B17C" value="Yes" /></td>
    <td>D. 2012 <input type="checkbox" name="B1D" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="4"><hr /></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center"><strong>18. </strong></div></td>
    </tr>
  <tr>
    <td> </td>
    <td>A. <input type="checkbox" name="B18A" value="Yes" /></td>
    <td>B. <input type="checkbox" name="B18B" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td>C. <input type="checkbox" name="B18C" value="Yes" /></td>
    <td>D. <input type="checkbox" name="B18D" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="4"><hr /></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center"><strong>19.</strong></div></td>
    </tr>
  <tr>
    <td> </td>
    <td>A. <input type="checkbox" name="B19A" value="Yes" /></td>
    <td>B. <input type="checkbox" name="B19B" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td>C. <input type="checkbox" name="B19C" value="Yes" /></td>
    <td>D. <input type="checkbox" name="B19D" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="4"><hr /></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center"><strong>20.</strong></div></td>
    </tr>
  <tr>
    <td> </td>
    <td>A. <input type="checkbox" name="B20A" value="Yes" /></td>
    <td>B. <input type="checkbox" name="B20B" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="4"><div align="center">
      <hr />
      <strong></strong></div></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center"><strong>21.</strong></div></td>
    </tr>
  <tr>
    <td> </td>
    <td>A. <input type="checkbox" name="B21A" value="Yes" /></td>
    <td>B. <input type="checkbox" name="B21B" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td>C. <input type="checkbox" name="B21C" value="Yes" /></td>
    <td>D. <input type="checkbox" name="B21D" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="4"><hr /></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center"><strong>22.</strong></div></td>
    </tr>
  <tr>
    <td> </td>
    <td>A. <input type="checkbox" name="B22A" value="Yes" /></td>
    <td>B. <input type="checkbox" name="B22B" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td>C. <input type="checkbox" name="B22C" value="Yes" /></td>
    <td>D. <input type="checkbox" name="B20D" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="4"><hr /></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center"><strong>23.</strong></div></td>
    </tr>
  <tr>
    <td> </td>
    <td>A. <input type="checkbox" name="B23A" value="Yes" /></td>
    <td>B. <input type="checkbox" name="B23B" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td>C. <input type="checkbox" name="B23C" value="Yes" /></td>
    <td>D. <input type="checkbox" name="B23D" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="4"><div align="center"><strong>24.</strong></div></td>
    </tr>
  <tr>
    <td> </td>
    <td>A. <input type="checkbox" name="B24A" value="Yes" /></td>
    <td>B. <input type="checkbox" name="B24B" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td>C. <input type="checkbox" name="B24C" value="Yes" /></td>
    <td>D. <input type="checkbox" name="B24D" value="Yes" /></td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="4"><hr /></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center"></div></td>
    </tr>
  <tr>
    <td colspan="4"><div align="center">
      <input type="submit" name="submit" value="Submit" />
    </div></td>
  </tr>
  <tr>
    <td colspan="4"> </td>
  </tr>
</table>
<p>

</form>
<p>

</body>
</html>

The posted code contains the following error -

 

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in your_file.php on line 24

 

When learning php, developing php code, or debugging php code, always turn on full php error_reporting (E_ALL or the equivalent integer value when in a .htaccess file) and set display_errors on in the master php.ini, a .htaccess file (when php is running as an Apache server module), or a local php.ini (when php is running as a CGI wrapper) to get php to help you.

 

Fatal parse errors prevent a script from running so putting any error_reporting or display_errors settings in a script has no effect for parse errors.

Hi Ken this is one of many forms (the others all work!) as it is used by foreign students I have to keep the format the same and some of the other forms have more than one correct answer hence the check boxes. I switched on the error reporting but still drawing a blank page though...

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.