Jump to content

POSTING FORM DATA


allie.nicole

Recommended Posts

Hi everyone!

 

So, I have recently become interested in the world of webpage design and HTML coding. Thus far, I have created a  few simple HTML webpages, the first of which includes some basic facts and information on the state of NC. Everything has gone rather smoothly for me until this point, but I would now like to incorporate a bit of PHP into my knowledge of web development.

 

First, I would like to include a form on my NC page that once submitted, goes to a new PHP page displaying the inputted data to the screen.

On the new page, I am attempting to include files: a header and footer.

 

On my other couple of pages for which I would like to add server side includes.

And lastly, if possible, it would be great if I could learn how to add some additional features like sending e-mails or displaying the date. Any advice or tips on how to go about this would be greatly appreciated!

Link to comment
Share on other sites

Alright Allie, welcome.

 

First off, it would help a lot more if you post the HTML code you already have for the NC page. 

Then I can explain to you how the data is sent.

 

Right now, all i can tell you is that the key to it is in your opening

tag.  You'll have attributes in it like

- method  ... This is the attribute that determines how your data is sent

- action .... This is the attribute that contains your PHP file... for data reception.

 

there are more, but there not exactly necessary at this time to know, but if you're curious.

- name

- enctype

- and a few more that I can't remember.

Link to comment
Share on other sites

Zane,

 

Below is the HTML coding that I used to create northcarolina.html:

<html>

<head>

	<title>All About North Carolina!</title>

</head>

<body>

<img src=http://www.vincecartersanctuary.org/Portals/61544/images//NCSateFlag.jpg align="right" height="100" width="100" alt="Official Flag of the State of NC"/>

<h2>North Carolina</h2>

<h3><blockquote>"Every kid - no matter where he or she lives in NC - must graduate from high school with what it really takes to succeed in a career, in a two- 	or four-year college or in Technical training."</blockquote><br/>

<P ALIGN="RIGHT">- NC Governor Beverly Perdue</h3>

<P><P><em>Interested in learning more about Governor Perdue and what she has done for the people of North Carolina? <a href="http://www.state.nc.us"><b>Click here</a></b> to visit the Official Web Site of the State of NC.</em></P></P>


<body bgcolor="lightblue">


</body>

</html>

 

As I mentioned previously, I have only created a fairly simple page so far.

 

EDITed for

 tags.

Link to comment
Share on other sites

 

You don't need this line, because you've already opened the body tag .. right before your img tag.  So get rid of that for starters.

Next, you need to actually have a form.

You can easily start one where you deleted that line I'm talking about.

 

"Every kid - no matter where he or she lives in NC - must graduate from high school with what it really takes to succeed in a career, in a two- 	or four-year college or in Technical training."


- NC Governor Beverly Perdue


Interested in learning more about Governor Perdue and what she has done for the people of North Carolina? Click here to visit the Official Web Site of the State of NC.
        </pre>
<form action="'yourPHPfile.php'" method="'POST'">
              
        </form

 

If you still want to keep the lightblue, you can always add it to the opening body tag... just as you did with the one I told you to delete.

 

 

Link to comment
Share on other sites

Thanks for the tutorial. I have worked on the HTML page a bit more, and I have decided to create a quiz on random facts about North Carolina. So far, I have created the code for most of the questions (I believe I will be using about 10, and I have created 7 so far). I also have my 'Submit' button in place. I am now at the stage where I'd like to be able to have the quiz scored automatically. Once the 'Get Score' button is clicked, I want to have the results of the quiz displayed on the PHP page. Below is the code that I have finished so far on the HTML page:

 

<html>

<head>

	<title>All About North Carolina!</title>

</head>

<body bgcolor="lightblue">

<img src=http://www.vincecartersanctuary.org/Portals/61544/images//NCSateFlag.jpg align="right" height="100" width="100" alt="Official Flag of the State of NC"/>

<h2>North Carolina</h2>

<h3><blockquote>"Every kid - no matter where he or she lives in NC - must graduate from high school with what it really takes to succeed in a career, in a two- 	or four-year college or in Technical training."</blockquote><br/>

<P ALIGN="RIGHT">- NC Governor Beverly Perdue</h3>

<P><P><em>Interested in learning more about Governor Perdue and what she has done for the people of North Carolina? <a href="http://www.state.nc.us"><b>Click here</a></b> to visit the Official Web Site of the State of NC.</em></P></P>


<P>

<blockquote>Have you enjoyed the tidbits of information provided here about the Tar Heel State? If so, take the opportunity to 	gather even more facts! Subscribe to our mailing list to receive our weekly newsletter that contains the latest news about North Carolina in addition to interesting articles and stunning photos that have been submitted by our readers. Simply enter your name and e-mail address below to sign up!</blockquote> 


<P>

<form action='quizresults.php' method='POST'>
        <span>Name:</span><input type='text' name='name' />
        <span>Email:</span><input type='text' name='email' />
<input type='submit' value="Submit"/>
</form>

<P>
<P>
<P>

<B>How well do you know your facts about North Carolina? Take this trivia quiz for fun! Select the best answer for each question, then click 'Submit' to see your score.</B>

<P>

<form action='NorthCarolina.php' method='POST'>
<ol>
<li>What is the state flower of North Carolina?<br>
<input type="radio" value="A" name="no1"> A. Poppy<br>
<input type="radio" value="B" name="no1"> B. American Dogwood<br>
<input type="radio" value="C" name="no1"> C. Black-Eyed Susan<br>
<input type="radio" value="D" name="no1"> D. Bluebonnet<br>
</li>
<br>
<li>The state bird of North Carolina is the Robin.<br>
<input type="radio" value="true" name="no2">True<br>
<input type="radio" value="false" name="no2">False<br>
</li>
<br>
<li>What is the capital city of North Carolina?<br>
<input type="radio" value="A" name="no3"> A. Charlotte<br>
<input type="radio" value="B" name="no3"> B. Winston-Salem<br>
<input type="radio" value="C" name="no3"> C. Raleigh<br>
<input type="radio" value="D" name="no3"> D. Greenville<br>
</li>
<br>
<li>What is the <em>largest</em> city in North Carolina?<br>
<input type="radio" value="A" name="no4"> A. Murphy<br>
<input type="radio" value="B" name="no4"> B. Hayesville<br>
<input type="radio" value="C" name="no4"> C. Charlotte<br>
<input type="radio" value="D" name="no4"> D. Concord<br>
</li>
<br>
<li>Which of these is a major river in North Carolina?<br>
<input type="radio" value="A" name="no5"> A. Roanoke<br>
<input type="radio" value="B" name="no5"> B. Neuse<br>
<input type="radio" value="C" name="no5"> C. Yadkin<br>
<input type="radio" value="D" name="no5"> D. All of the above<br>
</li>
<br>
<li>Virginia is a bordering state of North Carolina.<br>
<input type="radio" value="true" name="no6">True<br>
<input type="radio" value="false" name="no6">False<br>
</li>
<br>
<li>Name a mountain range in North Carolina.<br>
<input type="radio" value="A" name="no7"> A. Appalachians<br>
<input type="radio" value="B" name="no7"> B. Rockies<br>
<input type="radio" value="C" name="no7"> C. Adirondacks<br>
<input type="radio" value="D" name="no7"> D. Cascades<br>
</li>
<br>

 

It looks like everything on the HTML page is correct so far, and I believe that my 'Get Score' button directs to the proper page so far. I am thinking about removing the name and e-mail fields. Do you have any suggestions on how to get started on the PHP side of things? Thanks!

 

When you post code, please put it in between

 <-- code tags --> 

Link to comment
Share on other sites

Looks good Allie, ... you don't exactly have a doctype set so telling you to change

to

won't make much difference.

 

Maybe you just forgot to post the rest of your HTML, because the bottom half is missing.

There is no submit button for your second form (The quiz form)..  which I don't understand why it points to NorthCarolina.php

 

Your first form points to quizresults.php, but it only has two form fields... do you even need that form anymore?

 

  • tags are automatically put on another line.. so there's no point in having a

    after each list item .. aka

  •  

    So long as you have a submit button, you should be ready for your PHP.. 

    This will involve using arrays and the use of the isset function.

     

    The first thing to do in your PHP script... that is after you fix your HTML.. is to check for the submit button

    In order to check for it, it must have a name.

     

    So if your submit button looks like this

     

    Your PHP will look something like this

    if(isset($_POST['submit'])) {
    
    /*
       Quiz grading code inside here
    */
    
    }
    ?>
    

     

    If you can, provide me with a link to your page so I can see what it looks like.. and offer a few tips

    Link to comment
    Share on other sites

    Hi Zane,

     

    At first, I thought that <br /> was the correct way to enter it, but then again I wasn't sure if it made much difference - regardless, I have corrected that. I looked back over my last post, and it looks like I accidentally left out the line of code that creates my 'Submit' button - sorry about that. I know that the <li> tags will be put on another line, but I entered the <br> to put an additional line between each of the questions so that it wouldn't look so crowded. Is there a better way to do this? I've removed the code for the first form and linked the existing one to quizresults.php. Also, I have completed the code for all of the quiz questions. My final HTML page looks something like this:

     

    
    <html>
    
    <head>
    
    	<title>All About North Carolina!</title>
    
    </head>
    
    <body bgcolor="lightblue">
    
    <img src=http://www.vincecartersanctuary.org/Portals/61544/images//NCSateFlag.jpg align="right" height="100" 
    
    width="100" alt="Official Flag of the State of NC"/>
    
    <h2>North Carolina</h2>
    
    <h3><blockquote>"Every kid - no matter where he or she lives in NC - must graduate from high school with what it 
    
    really takes to succeed in a career, in a two- 	or four-year college or in Technical training."</blockquote><br/>
    
    <P ALIGN="RIGHT">- NC Governor Beverly Perdue</h3>
    
    <P><P><em>Interested in learning more about Governor Perdue and what she has done for the people of North Carolina? <a 
    
    href="http://www.state.nc.us"><b>Click here</a></b> to visit the Official Web Site of the State of NC.</em></P></P>
    
    
    <P>
    <P>
    
    <B><blockquote>How well do you know your facts about North Carolina? Take this trivia quiz for fun! Select the best 
    
    answer for each question, then click 'Submit' to see your score.</B></blockquote>
    
    <P>
    
    <form action='quizresults.php' method='POST'>
    <ol>
    <li>What is the state flower of North Carolina?<br/>
    <input type="radio" value="A" name="no1"> A. Poppy<br/>
    <input type="radio" value="B" name="no1"> B. American Dogwood<br/>
    <input type="radio" value="C" name="no1"> C. Black-Eyed Susan<br/>
    <input type="radio" value="D" name="no1"> D. Bluebonnet<br/>
    </li>
    <br/>
    <li>The state bird of North Carolina is the Robin.<br/>
    <input type="radio" value="true" name="no2">True<br/>
    <input type="radio" value="false" name="no2">False<br/>
    </li>
    <br/>
    <li>What is the capital city of North Carolina?<br/>
    <input type="radio" value="A" name="no3"> A. Charlotte<br/>
    <input type="radio" value="B" name="no3"> B. Winston-Salem<br/>
    <input type="radio" value="C" name="no3"> C. Raleigh<br/>
    <input type="radio" value="D" name="no3"> D. Greenville<br>
    </li>
    <br/>
    <li>North Carolina has 100 counties in total.<br/>
    <input type="radio" value="true" name="no4">True<br/>
    <input type="radio" value="false" name="no4">False<br/>
    </li>
    <br/>
    <li>Which of these is a major river in North Carolina?<br/>
    <input type="radio" value="A" name="no5"> A. Roanoke<br/>
    <input type="radio" value="B" name="no5"> B. Neuse<br/>
    <input type="radio" value="C" name="no5"> C. Yadkin<br/>
    <input type="radio" value="D" name="no5"> D. All of the above<br/>
    </li>
    <br/>
    <li>Virginia is a bordering state of North Carolina.<br/>
    <input type="radio" value="true" name="no6">True<br/>
    <input type="radio" value="false" name="no6">False<br/>
    </li>
    <br/>
    <li>Name a mountain range in North Carolina.<br/>
    <input type="radio" value="A" name="no7"> A. Appalachians<br/>
    <input type="radio" value="B" name="no7"> B. Rockies<br/>
    <input type="radio" value="C" name="no7"> C. Adirondacks<br/>
    <input type="radio" value="D" name="no7"> D. Cascades<br/>
    </li>
    <br/>
    <li>In what city/town is the famous marine base "Cherry Point" located?<br/>
    <input type="radio" value="A" name="no8"> A.Havelock, NC<br/>
    <input type="radiO" value="B" name="no8"> B.Goldsboro, NC<br/>
    <input type="radio" value="C" name="no8"> C.Wilmington, NC<br/>
    <input type="radio" value="D" name="no8"> D.New Bern, NC<br/>
    </li>
    <br/>
    <li>Tobacco is <b>one</b> of the leading industries in the state.<br/>
    <input type="radio" value="true" name="no9">True<br/>
    <input type="radio" value="true" name="no9">False<br/>
    </li>
    <br/>
    <li>What is the <em>largest</em> city in North Carolina?<br/>
    <input type="radio" value="A" name="no10"> A. Concord<br/>
    <input type="radio" value="B" name="no10"> B. Greensboro<br/>
    <input type="radio" value="C" name="no10"> C. Charlotte<br/>
    <input type="radio" value="D" name="no10"> D. Fayetteville<br/>
    </li>
    </ol>
    
    <P>
    
    <input type='submit' name='submit' value='Get Score'/>
    
    
    </body>
    
    </html>
    
    
    I am now back to working on the PHP portion. I found some code from a couple of websites that suggests how to create the quiz results page, but it doesn't seem that I'm doing it quite right because it doesn't generate correctly. I will continue to work on this and post an update when I have made more progress. In a private message, I will send you a link to both my northcarolina.html page in addition to the attempted work that I have done thus far with quizresults.php. 

    Link to comment
    Share on other sites

    You HTML looks pretty much perfect now.

    I know that the

  • tags will be put on another line, but I entered the

    to put an additional line between each of the questions so that it wouldn't look so crowded. Is there a better way to do this?

  • Yes, and it's called CSS (Cascading Stylesheets)

     

    I wouldn't worry about it right now, but all it involves is putting this in your head tag

    <br />
    ol li {<br />
        padding-bottom: 10px;<br />
    }<br />
    
    

     

    Now you need to post the code for your quizresults.php page if you have any at all..

    I gave you the building blocks to it in my last post.

    Link to comment
    Share on other sites

    I've finished a rough draft of the PHP page, based on your advice and some other research that I've done online. I believe I must have some things incorrect, because I'm still unable to view the results, but whether or not it's entirely correct, I believe it represents a decent idea of what I'd like to accomplish. Below is the code:

     

    
    <HTML>
    
    <h2>'How Much Do You Know About North Carolina?' Quiz Results:</h2>
    
    </HTML>
    
    
    <?php
    
    $score=0; 
    
    if(isset($_POST['submit'])) {
    
    
    }
    
    
    If ($no1="B")
    $score=$score+10;
    
    else {
    
    echo "The <strong>American Dogwood</strong> is the state flower of NC.
    
    ";
    
    }
    
    If ($no2="false")
    $score=$score+10; 
    
    else {
    
    echo "False. The state bird of NC is the <strong>cardinal</strong>.
    
    ";
    
    }
    
    If($no3="C")
    $score=$score+10; 
    
    else {
    
    echo "<strong>Raleigh</strong> is the capital of NC.
    
    ";
    
    }
    
    If($no4="true")
    $score=$score+10;
    
    If($no5="D")
    $score=$score+10; 
    
    If($no6="true")
    $score=$score+10;
    
    If($no7="A")
    $score=$score+10; 
    
    else {
    
    echo "Though all of these are mountain ranges, the <strong>Appalachians</strong> is the only one found in NC.
    
    ";
    
    }
    
    If($no8="A")
    $score=$score+10; 
    
    else {
    
    echo "The historical marine base, Cherry Point, is located in the town of <strong>Havelock, NC</strong>. 
    
    "; 
    
    }
    
    If($no9="true")
    $score=$score+10; 
    
    else {
    
    echo "Tobacco <strong>is</strong> one of the leading industries in NC. Others include chemical products and textiles.
    
    ";
    
    }
    
    If($no10="C")
    $score=$score+10; 
    
    else {
    
    echo "<strong>Charlotte</strong> is the largest city in NC.
    
    ";
    
    }
    
    <P>
    <P>
    
    <strong>Your score on the "All About North Carolina" quiz is ".$score."
    
    ";
    
    
    ?>
    
    

    Link to comment
    Share on other sites

    Close, but no cigar.

     

    First off, forget about tags and focus mainly on your PHP right now, you can add your HTML in later.  The reason I say this is because you open an html tag and then close it directly before you display output.  HTML output is meant to be inside those html tags, but regardless, you can still use HTML tags.. like etc... just fine.  The browser will figure it out.

     

    As for your PHP, you're going about getting the data all wrong.

     

    
    $score=0; 
    
    if(isset($_POST['submit'])) {
    
    
    }
    

    This part is the only part that's correct..  logic-wise.  Syntax-wise, everything is fine.

     

    The point of having isset( $_POST['submit'] ) is to check that a user USED the form...

    Then, once you know that they used the form, you can do your coding...

     

    and you get your values the same way as the submit button

    For instance, if you want to check the value of no1, do this, similar to the way you did already.

    if ($_POST['no1'] =="B")  {
         $score += 10;
    } else {
         $errors[] = "The American Dogwood is the state flower of NC.";
    }
    

     

    Note the use of TWO equals signs  ... This is used to COMPARE

    Note the use of += to add onto $score

    Note the use of $errors[]

      it will add on to that array.  Then you can just echo everything at once.

     

    There is plenty to learn and plenty more to learn, but see if you can take this and come up with something.

     

    Oh, and to show your errors.. use this little snippet of code at the end

    foreach($errors as $error)  echo $error . "
    \n";
    

    Link to comment
    Share on other sites

    So, I have edited the code for the PHP file once again, and when trying to view it, I get this error:

     

    Parse error: syntax error, unexpected '<' in C:\wamp\www\quizresults.php on line 103.

     

    After looking at Line 103, it looks like the only thing that line contains is a piece of code for a paragraph break. I am assuming that this isn't it, but that it lies near the referenced line somewhere. Can someone else spot what the problem might be based on the code below?

     

    
    <?php phpinfo(); ?>
    
    <HTML>
    
    <h2>'How Much Do You Know About North Carolina?' Quiz Results:</h2>
    
    
    <?php
    
    $score=0; 
    
    if(isset($_POST['submit'])) {
    
    }
    
    
    if ($_POST['no1'] =="B")  {
         $score += 10;
    } else {
         $errors[] = "The <strong>American Dogwood</strong> is the state flower of NC.";
    }
    
    
    if ($_POST['no2'] =="false") {
    $score += 10; 
    
    } else {
    
    $errors[] = "False. The state bird of NC is the <strong>cardinal</strong>.";
    
    }
    
    if($_POST['no3'] =="C") {
    $score += 10; 
    
    } else {
    
    $errors[] = "<strong>Raleigh</strong> is the capital of NC.";
    
    }
    
    
    if($_POST['no4'] == "true") {
    $score += 10;
    
    
    
    if($_POST['no5'] == "D") {
    $score += 10; 
    
    
    
    if($_POST['no6'] == "true") {
    $score += 10;
    
    
    if($_POST['no7'] == "A") {
    $score += 10; 
    
    } else {
    
    $errors[] = "Though all of these are mountain ranges, the <strong>Appalachians</strong> is the only one found in NC.
    
    ";
    
    }
    
    if($_POST['no8'] == "A") {
    $score += 10; 
    
    } else {
    
    $errors[] = "The historical marine base, Cherry Point, is located in the town of <strong>Havelock, NC</strong>. 
    
    "; 
    
    }
    
    
    if($_POST['no9'] == "true") {
    $score += 10; 
    
    } else {
    
    $errors[] = "Tobacco <strong>is</strong> one of the leading industries in NC. Others include chemical products and textiles.
    
    ";
    
    }
    
    if($_POST['no10'] == "C") {
    $score += 10;
    
    } else {
    
    
    $errors[] = "<strong>Charlotte</strong> is the largest city in NC.
    
    ";
    
    }
    
    <P>
    <P>
    
    echo "
    
    <strong>Your score on the "All About North Carolina" quiz is ".$score."</strong>
    
    ";
    
    foreach($errors as $error)  echo $error . "<br />\n";
    
    ?>
    
    </HTML>
    
    

     

    Thanks!

    Link to comment
    Share on other sites

    if($_POST['no10'] == "C") {
    $score += 10;
    
    } else {
    
    
    $errors[] = "Charlotte is the largest city in NC.
    
    ";
    
    }
    
    
         // NOT PHP CODE
    
         // NOT PHP CODE
    
    echo "
    
    Your score on the "All About North Carolina" quiz is ".$score."
    
    ";
    

     

    You get this error because the P tag isn't a php function or php anything... it's pure HTML.  PHP doesn't parse HTML code like a browser, it assumes you mean

    P is greater than absolutely nothing at all and

    P is less than absolutely nothing at all

     

    And you got to admit, that makes absolutely no sense at all.

    Link to comment
    Share on other sites

    Again, I have modified my PHP code to correct what seemed to be the issue by choosing to remove all HTML code. It still seems that I am getting "Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\wamp\www\quizresults.php" on line 106, which is contained in this section of code:

     

    
    if($_POST['no10'] == "C") {
    $score += 10;
    
    } else {
    
    
    $errors[] = "Charlotte is the largest city in NC.
    
    ";
    
    }
    
    
    echo "
    
    Your score on the "All About North Carolina" quiz is ".$score.";
    
    
    foreach($errors as $error) echo $error . "<br />\n";
    
    ?>
    
    </HTML>
    
    

     

    In particular, Line 106 reads:

     

    
    Your score on the "All About North Carolina" quiz is ".$score.";
    
    

     

    Is anyone able to spot an error that has been made that I am obviously overlooking? I have exhausted the little knowledge of PHP that I have in addition to all of my known resources, but can't seem to get this corrected. Any suggestions would be greatly appreciated.

    Link to comment
    Share on other sites

    I have done a bit more work on the PHP file - I decided to make it simpler by removing all of the HTML. Once I did that, I no longer get the same error, but this error appears instead:

     

    Parse error: syntax error, unexpected $end, expecting T_VARIABLE or T_DOLLAR_OPEN_CURLY_BRACES or T_CURLY_OPEN in C:\wamp\www\quizresults.php on line 82

     

    It looks like Line 82 is a couple of lines below the closing tag of the code. After my edits, my code looks like this:

     

    
    <?php phpinfo(); ?>
    
    
    <?php
    
    $score=0; 
    
    if(isset($_POST['submit'])) {
    
    }
    
    
    if ($_POST['no1'] =="B")  {
    $score += 10;
    } else {
    $errors[] = "The American Dogwood is the state flower of NC.";
    }
    
    
    if ($_POST['no2'] =="false") {
    $score += 10; 
    } else {
    $errors[] = "False. The state bird of NC is the cardinal.";
    }
    
    
    if($_POST['no3'] =="C") {
    $score += 10; 
    } else {
    $errors[] = "Raleigh is the capital of NC.";
    }
    
    
    if($_POST['no4'] == "true") {
    $score += 10;
    }
    
    
    if($_POST['no5'] == "D") {
    $score += 10; 
    }
    
    
    if($_POST['no6'] == "true") {
    $score += 10;
    }
    
    
    if($_POST['no7'] == "A") {
    $score += 10; 
    } else {
    $errors[] = "Though all of these are mountain ranges, the Appalachians is the only one found in NC.";
    }
    
    
    if($_POST['no8'] == "A") {
    $score += 10; 
    } else {
    $errors[] = "The historical marine base, Cherry Point, is located in the town of Havelock, NC."; 
    }
    
    
    if($_POST['no9'] == "true") {
    $score += 10; 
    } else {
    $errors[] = "Tobacco is one of the leading industries in NC. Others include chemical products and textiles.";
    }
    
    
    if($_POST['no10'] == "C") {
    $score += 10;
    } else {
    $errors[] = "Charlotte is the largest city in NC.";
    }
    
    
    "Your score on the All About North Carolina quiz is ".$score.";
    
    
    ?>
    
    

     

    In addition to removing all HTML, I have double-checked that all of my brackets have an open and close. Based on what I have learned so far, everything looks to be consistent, but apparently my browser is expecting something else. Hopefully, I didn't create any more issues with the edits I did, and it is just a simple fix that I don't recognize because I am not yet too familiar with PHP. Does anyone have an idea regarding why I cannot get rid of this error?

    Link to comment
    Share on other sites

    Now no errors, but blank page once 'Get Score' is selected on northcarolina.html. Code is below:

     

    
    <?php
    
    error_reporting(E_ALL);
    ini_set('display_errors', true);
    
    $score=0; 
    
    if(isset($_POST['submit'])) {
    
    }
    
    
    if ($_POST['no1'] =="B")  {
    $score += 10;
    } else {
    $errors[] = "The American Dogwood is the state flower of NC.";
    }
    
    
    if ($_POST['no2'] =="false") {
    $score += 10; 
    } else {
    $errors[] = "False. The state bird of NC is the cardinal.";
    }
    
    
    if($_POST['no3'] =="C") {
    $score += 10; 
    } else {
    $errors[] = "Raleigh is the capital of NC.";
    }
    
    
    if($_POST['no4'] == "true") {
    $score += 10;
    }
    
    
    if($_POST['no5'] == "D") {
    $score += 10; 
    }
    
    
    if($_POST['no6'] == "true") {
    $score += 10;
    }
    
    
    if($_POST['no7'] == "A") {
    $score += 10; 
    } else {
    $errors[] = "Though all of these are mountain ranges, the Appalachians is the only one found in NC.";
    }
    
    
    if($_POST['no8'] == "A") {
    $score += 10; 
    } else {
    $errors[] = "The historical marine base, Cherry Point, is located in the town of Havelock, NC."; 
    }
    
    
    if($_POST['no9'] == "true") {
    $score += 10; 
    } else {
    $errors[] = "Tobacco is one of the leading industries in NC. Others include chemical products and textiles.";
    }
    
    
    if($_POST['no10'] == "C") {
    $score += 10;
    } else {
    $errors[] = "Charlotte is the largest city in NC.";
    
    echo"
    
    Your score on the All About North Carolina quiz is ".$score;
    
    }
    
    ?>
    
    

    Link to comment
    Share on other sites

    if(isset($_POST['submit'])) {
    
    }
    

     

    You get a blank page because of this....

     

    if($_POST['no10'] == "C") {
    $score += 10;
    } else {
    $errors[] = "Charlotte is the largest city in NC.";
    
    echo"
    
    Your score on the All About North Carolina quiz is ".$score;
    
    }
    

    If you answer incorrectly for question 10 it will echo something, because you end your else brace after your score statement...

    You need to end the else BEFORE the score statement.

     

    In other words,, your code should look like this

    ON TOP

    if(isset($_POST['submit'])) {
    

    and ON BOTTOM

    if($_POST['no10'] == "C") {
    $score += 10;
    } else {
    $errors[] = "Charlotte is the largest city in NC.";
    }
    
    echo "Your score on the All About North Carolina quiz is ".$score;
    }
    

     

    It really really REALLY helps to indent your code.

    Link to comment
    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.