Jump to content

multiple choice quiz not working


owosso

Recommended Posts

My site asks data questions that require an answer of yes, no or maybe. When the user clicks submit, the data is emailed to me and a "Thank You" screen appears to the user. I've created multiple choice php coding but it's working incorrectly. When submitting, the user receives an error screen full of code, and the data comes to my email in an incomplete format.I have narrowed the problem down to this section of coding - everything else works okay. Here is my html code:

<h2>4.Goals for your website</h2>     <table width="416" cellspacing="5">       <tr>         <td width="246"><p>Create awareness and identity </p></td>         <td width="30"><center>           <p>Yes<br />             <input type="checkbox" name="create" value="1" />           </p>         </center></td>         <td width="36"><center>           <p>No<br />             <input type="checkbox" name="create" value="2" />           </p>         </center></td>         <td width="69"><center>           <p>Maybe<br />             <input type="checkbox" name="create" value="3" />           </p>         </center></td>       </tr>       <tr>         <td><p>Educate, provide information </p></td>         <td><center>           <p>Yes<br />             <input type="checkbox" name="educate" value="1" />           </p>         </center></td>         <td><center>           <p>No<br />             <input type="checkbox" name="educate" value="2" />           </p>         </center></td>         <td><center>           <p>Maybe<br/>             <input type="checkbox" name="educate" value="3" />           </p>         </center></td>       </tr>       <tr>         <td><p>Promote a service or product </p></td>         <td><center>           <p>Yes<br />             <input type="checkbox" name="promote" value="1" />           </p>         </center></td>         <td><center>           <p>No<br />             <input type="checkbox" name="promote" value="2" />           </p>         </center></td>         <td><center>           <p>Maybe<br />             <input type="checkbox" name="promote" value="3" />           </p>         </center></td>       </tr>       <tr>         <td><p>Sell (online) a service or product </p></td>         <td><center>           <p>Yes<br />             <input type="checkbox" name="sell" value="1" />           </p>         </center></td>         <td><center>           <p>No<br />             <input type="checkbox" name="sell" value="2" />           </p>         </center></td>         <td><center>           <p>Maybe<br />             <input type="checkbox" name="sell" value="3" />           </p>         </center></td>       </tr>     </table>

Here is my php code:

	unset($_POST);echo ' Case 1 : yes<br />';$_POST['create'] = 'yes';$msg = "CREATE AWARENESS AND IDENTITY: " . (($_POST['create'] == "yes") ? "yes" : (($_POST['create'] == 'no') ? "no" : "maybe" )) . "\n";echo '$_POST[\'create\'] is ' . $_POST['create'] . '<br />';echo $msg . '<br /><br />';unset($_POST);echo ' Case 2 : no<br />'; $_POST['create'] = 'no';$msg = "CREATE AWARENESS AND IDENTITY: " . (($_POST['create'] == 'yes') ? "yes" : (($_POST['create'] == 'no') ? "no" : "maybe" )) . "\n";echo '$_POST[\'create\'] is ' . $_POST['create'] . '<br />';echo $msg . '<br /><br />';unset($_POST);echo ' Case 3 : maybe<br />';$_POST['create'] = 'maybe';$msg = "CREATE AWARENESS AND IDENTITY: " . (($_POST['create'] == 'yes') ? "yes" : (($_POST['create'] == 'no') ? "no" : "maybe" )) . "\n";echo '$_POST[\'create\'] is ' . $_POST['create'] . '<br />';echo $msg . '<br />';unset($_POST);echo ' Case 1 : yes<br />';$_POST['create'] = 'yes';$msg = "EDUCATE, PROVIDE INFORMATION: " . (($_POST['educate'] == "yes") ? "yes" : (($_POST['create'] == 'no') ? "no" : "maybe" )) . "\n";echo '$_POST[\'create\'] is ' . $_POST['create'] . '<br />';echo $msg . '<br /><br />';unset($_POST);echo ' Case 2 : no<br />'; $_POST['create'] = 'no';$msg = "EDUCATE, PROVIDE INFORMATION: " . (($_POST['educate'] == 'yes') ? "yes" : (($_POST['create'] == 'no') ? "no" : "maybe" )) . "\n";echo '$_POST[\'create\'] is ' . $_POST['create'] . '<br />';echo $msg . '<br /><br />';unset($_POST);echo ' Case 3 : maybe<br />';$_POST['create'] = 'maybe';$msg = "EDUCATE, PROVIDE INFORMATION: " . (($_POST['educate'] == 'yes') ? "yes" : (($_POST['create'] == 'no') ? "no" : "maybe" )) . "\n";echo '$_POST[\'create\'] is ' . $_POST['create'] . '<br />';echo $msg . '<br />';unset($_POST);echo ' Case 1 : yes<br />';$_POST['create'] = 'yes';$msg = "PROMOTE A SERVICE OR PRODUCT: " . (($_POST['promote'] == "yes") ? "yes" : (($_POST['create'] == 'no') ? "no" : "maybe" )) . "\n";echo '$_POST[\'create\'] is ' . $_POST['create'] . '<br />';echo $msg . '<br /><br />';unset($_POST);echo ' Case 2 : no<br />'; $_POST['create'] = 'no';$msg = "PROMOTE A SERVICE OR PRODUCT: " . (($_POST['promote'] == 'yes') ? "yes" : (($_POST['create'] == 'no') ? "no" : "maybe" )) . "\n";echo '$_POST[\'create\'] is ' . $_POST['create'] . '<br />';echo $msg . '<br /><br />';unset($_POST);echo ' Case 3 : maybe<br />';$_POST['create'] = 'maybe';$msg = "PROMOTE A SERVICE OR PRODUCT: " . (($_POST['promote'] == 'yes') ? "yes" : (($_POST['create'] == 'no') ? "no" : "maybe" )) . "\n";echo '$_POST[\'create\'] is ' . $_POST['create'] . '<br />';echo $msg . '<br />';	unset($_POST);echo ' Case 1 : yes<br />';$_POST['create'] = 'yes';$msg = "SELL A SERVICE OR PRODUCT: " . (($_POST['sell'] == "yes") ? "yes" : (($_POST['create'] == 'no') ? "no" : "maybe" )) . "\n";echo '$_POST[\'create\'] is ' . $_POST['create'] . '<br />';echo $msg . '<br /><br />';unset($_POST);echo ' Case 2 : no<br />'; $_POST['create'] = 'no';$msg = "SELL A SERVICE OR PRODUCT: " . (($_POST['sell'] == 'yes') ? "yes" : (($_POST['create'] == 'no') ? "no" : "maybe" )) . "\n";echo '$_POST[\'create\'] is ' . $_POST['create'] . '<br />';echo $msg . '<br /><br />';unset($_POST);echo ' Case 3 : maybe<br />';$_POST['create'] = 'maybe';$msg = "SELL A SERVICE OR PRODUCT: " . (($_POST['sell'] == 'yes') ? "yes" : (($_POST['create'] == 'no') ? "no" : "maybe" )) . "\n";echo '$_POST[\'create\'] is ' . $_POST['create'] . '<br />';echo $msg . '<br />';

Link to comment
Share on other sites

My site asks data questions that require an answer of yes, no or maybe. When the user clicks submit, the data is emailed to me and a "Thank You" screen appears to the user. I've created multiple choice php coding but it's working incorrectly. When submitting, the user receives an error screen full of code, and the data comes to my email in an incomplete format.I have narrowed the problem down to this section of coding - everything else works okay. Here is my html code:
<h2>4.Goals for your website</h2>     <table width="416" cellspacing="5">       <tr>         <td width="246"><p>Create awareness and identity </p></td>         <td width="30"><center>           <p>Yes<br />             <input type="checkbox" name="create" value="1" />           </p>         </center></td>         <td width="36"><center>           <p>No<br />             <input type="checkbox" name="create" value="2" />           </p>         </center></td>         <td width="69"><center>           <p>Maybe<br />             <input type="checkbox" name="create" value="3" />           </p>         </center></td>       </tr>       <tr>         <td><p>Educate, provide information </p></td>         <td><center>           <p>Yes<br />             <input type="checkbox" name="educate" value="1" />           </p>         </center></td>         <td><center>           <p>No<br />             <input type="checkbox" name="educate" value="2" />           </p>         </center></td>         <td><center>           <p>Maybe<br/>             <input type="checkbox" name="educate" value="3" />           </p>         </center></td>       </tr>       <tr>         <td><p>Promote a service or product </p></td>         <td><center>           <p>Yes<br />             <input type="checkbox" name="promote" value="1" />           </p>         </center></td>         <td><center>           <p>No<br />             <input type="checkbox" name="promote" value="2" />           </p>         </center></td>         <td><center>           <p>Maybe<br />             <input type="checkbox" name="promote" value="3" />           </p>         </center></td>       </tr>       <tr>         <td><p>Sell (online) a service or product </p></td>         <td><center>           <p>Yes<br />             <input type="checkbox" name="sell" value="1" />           </p>         </center></td>         <td><center>           <p>No<br />             <input type="checkbox" name="sell" value="2" />           </p>         </center></td>         <td><center>           <p>Maybe<br />             <input type="checkbox" name="sell" value="3" />           </p>         </center></td>       </tr>     </table>

Here is my php code:

	unset($_POST);echo ' Case 1 : yes<br />';$_POST['create'] = 'yes';$msg = "CREATE AWARENESS AND IDENTITY: " . (($_POST['create'] == "yes") ? "yes" : (($_POST['create'] == 'no') ? "no" : "maybe" )) . "\n";echo '$_POST[\'create\'] is ' . $_POST['create'] . '<br />';echo $msg . '<br /><br />';unset($_POST);echo ' Case 2 : no<br />'; $_POST['create'] = 'no';$msg = "CREATE AWARENESS AND IDENTITY: " . (($_POST['create'] == 'yes') ? "yes" : (($_POST['create'] == 'no') ? "no" : "maybe" )) . "\n";echo '$_POST[\'create\'] is ' . $_POST['create'] . '<br />';echo $msg . '<br /><br />';unset($_POST);echo ' Case 3 : maybe<br />';$_POST['create'] = 'maybe';$msg = "CREATE AWARENESS AND IDENTITY: " . (($_POST['create'] == 'yes') ? "yes" : (($_POST['create'] == 'no') ? "no" : "maybe" )) . "\n";echo '$_POST[\'create\'] is ' . $_POST['create'] . '<br />';echo $msg . '<br />';unset($_POST);echo ' Case 1 : yes<br />';$_POST['create'] = 'yes';$msg = "EDUCATE, PROVIDE INFORMATION: " . (($_POST['educate'] == "yes") ? "yes" : (($_POST['create'] == 'no') ? "no" : "maybe" )) . "\n";echo '$_POST[\'create\'] is ' . $_POST['create'] . '<br />';echo $msg . '<br /><br />';unset($_POST);echo ' Case 2 : no<br />'; $_POST['create'] = 'no';$msg = "EDUCATE, PROVIDE INFORMATION: " . (($_POST['educate'] == 'yes') ? "yes" : (($_POST['create'] == 'no') ? "no" : "maybe" )) . "\n";echo '$_POST[\'create\'] is ' . $_POST['create'] . '<br />';echo $msg . '<br /><br />';unset($_POST);echo ' Case 3 : maybe<br />';$_POST['create'] = 'maybe';$msg = "EDUCATE, PROVIDE INFORMATION: " . (($_POST['educate'] == 'yes') ? "yes" : (($_POST['create'] == 'no') ? "no" : "maybe" )) . "\n";echo '$_POST[\'create\'] is ' . $_POST['create'] . '<br />';echo $msg . '<br />';unset($_POST);echo ' Case 1 : yes<br />';$_POST['create'] = 'yes';$msg = "PROMOTE A SERVICE OR PRODUCT: " . (($_POST['promote'] == "yes") ? "yes" : (($_POST['create'] == 'no') ? "no" : "maybe" )) . "\n";echo '$_POST[\'create\'] is ' . $_POST['create'] . '<br />';echo $msg . '<br /><br />';unset($_POST);echo ' Case 2 : no<br />'; $_POST['create'] = 'no';$msg = "PROMOTE A SERVICE OR PRODUCT: " . (($_POST['promote'] == 'yes') ? "yes" : (($_POST['create'] == 'no') ? "no" : "maybe" )) . "\n";echo '$_POST[\'create\'] is ' . $_POST['create'] . '<br />';echo $msg . '<br /><br />';unset($_POST);echo ' Case 3 : maybe<br />';$_POST['create'] = 'maybe';$msg = "PROMOTE A SERVICE OR PRODUCT: " . (($_POST['promote'] == 'yes') ? "yes" : (($_POST['create'] == 'no') ? "no" : "maybe" )) . "\n";echo '$_POST[\'create\'] is ' . $_POST['create'] . '<br />';echo $msg . '<br />';	unset($_POST);echo ' Case 1 : yes<br />';$_POST['create'] = 'yes';$msg = "SELL A SERVICE OR PRODUCT: " . (($_POST['sell'] == "yes") ? "yes" : (($_POST['create'] == 'no') ? "no" : "maybe" )) . "\n";echo '$_POST[\'create\'] is ' . $_POST['create'] . '<br />';echo $msg . '<br /><br />';unset($_POST);echo ' Case 2 : no<br />'; $_POST['create'] = 'no';$msg = "SELL A SERVICE OR PRODUCT: " . (($_POST['sell'] == 'yes') ? "yes" : (($_POST['create'] == 'no') ? "no" : "maybe" )) . "\n";echo '$_POST[\'create\'] is ' . $_POST['create'] . '<br />';echo $msg . '<br /><br />';unset($_POST);echo ' Case 3 : maybe<br />';$_POST['create'] = 'maybe';$msg = "SELL A SERVICE OR PRODUCT: " . (($_POST['sell'] == 'yes') ? "yes" : (($_POST['create'] == 'no') ? "no" : "maybe" )) . "\n";echo '$_POST[\'create\'] is ' . $_POST['create'] . '<br />';echo $msg . '<br />';

It looks like you left a lot out. Where's the form that's doing the submitting? Where is the email code? We don't know the workflow, and it could be crucial to solving the overall problem. I wouldn't assume everything else is working correctly, so best to show everything. What confuses me (especially since we can't see the form) is where you are getting the value's of the form in the the php file? Shouldn't you be getting the values from it? Why are you setting the value of $_POST['create']? $_POST is the array of form values that you be getting your data from Like I said, it's hard to help when we can't see the bigger picture.
Link to comment
Share on other sites

Why are you unsetting $_POST? Do you understand what unset does?
No, actually I don't. My knowledge of php is very limited - still in the learning stages. I took this code from another of my sites pages, it's code that was designed for me and I'm practicing with it by creating other pages. In regards to not providing enough information - do you need code for the complete page? I created the form in html. Is this the form you're looking for? It's directed to a php page and I included a portion of that page. Do you need the full page of code?(The reason I ask is because I've been previously scolded for including too much code.)
Link to comment
Share on other sites

Here's the manual page for unset:http://www.php.net/manual/en/function.unset.phpIt basically destroys a variable, it removes the variable from memory. So after you unset $_POST, $_POST and all of the data it contains is gone. You probably don't want to do that if you're trying to process the form.When you're processing the checkboxes, something like $_POST['create'] is going to contain a 1, 2, or 3 depending on which boxes they check. You can take that value and do whatever you want, you can just put the number in the email, have some code which converts the number to some text for the email, or just use text as the checkbox values instead of numbers. If you want the email to contain the text "Yes", "No", or "Maybe", it's probably best to just set those as the values for the checkboxes instead of converting numbers.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...