0

I am writing an HTML form which needs to be handled with a PHP file.

This is my client-side HTML code:

<h1>Marching Band Camp Registration</h1>
<p>Please fill out this form completely for your child to be eligible to participate in the upcoming marching season for the Eagle Band</p>

<h2>Student Information</h2>
    <form action="formhandle.php" method="post">
        First Name: <input type="text" name="firstname"><br>
        Last Name: <input type="text" name="lastname" />
    </form> 

    <form action="formhandle.php">
        <p>Please select your classification for the upcoming fall semester:
    <br /> <br />
        <input type="radio" name="class" value="F" checked="checked" /> Freshman
        <input type="radio" name="class" value="SO" checked="checked" /> Sophomore
        <input type="radio" name="class" value="J" checked="checked" /> Junior
        <input type="radio" name="class" value="SR" checked="checked" /> Senior
        <input type="submit">
        </p>
    </form> 

This is my server-side PHP code to handle it:

<?php $fn = $_POSTS["firstname"]; ?>

Thank you for registering, <?php echo $fn ; ?>  <br>

<?php $ln = $_POST["lastname"]; ?>
<?php echo $ln ; ?> 

Your Summary is as follows: <br>
<br>
<?php
    $_GET["class"]; 
     echo "Class:";
    echo "<br>";
    echo $_GET["class"]; 
?>

Only one item (Class) is showing up after submit. How can I make it so that all the items I want to show are shown? Am I doing something wrong with the $_POST and $_GET functions? I also want to add in other criteria, but if I can't get multiple items to show with just these three, I feel like I'm going to have a very bad time trying to add in even more criteria.

I'm making a longer form, that will have multiple inserted sections. I'm trying to figure out which to use, $_POST or $_GET. I tried one, turned it off, did the other, but I get the same problem of just either first name showing up, or just classification. My full ideal version has 1 radio button, 3 checkboxes, and 2 or 3 dropdown menu options. But I kept it minimal here to figure out why I can't get more than 1 to show simultaneously, regardless of which $_GET or $_POST I use. It will be one form so I only need ONE submit icon. One icon will submit the entire form, correct?

Kari
  • 85
  • 1
  • 9
  • What do you mean "all the items I want to show"? Your `class` inputs are radio buttons, so only one value can be submitted. – Jeto Sep 21 '18 at 21:43
  • `$_POSTS` !== `$_POST` afraid its just a TYPO – RiggsFolly Sep 21 '18 at 21:50
  • You're using $_GET instead of $_POST as well. Ensure your development environment is set up to display errors and you would have probably figured this out from all the undefined variable and undefined index warnings. https://stackoverflow.com/q/1053424/1255289 – miken32 Sep 21 '18 at 21:52
  • Actually there are two forms, one POST one GET. Not sure how that's going to work! – miken32 Sep 21 '18 at 21:54
  • @miken32 Ahh MISSED THAT. Then the `firstname` is in a form that will not be submitted – RiggsFolly Sep 21 '18 at 21:55
  • Put all the input fields into ONE `
    `
    – RiggsFolly Sep 21 '18 at 21:56
  • _Small note_ you are not coding on punch cards. You can use more than 72 characters on a line – RiggsFolly Sep 21 '18 at 21:58
  • `
    ` must be removed
    – Dean Sep 21 '18 at 21:58
  • This line `$_GET["class"]; ` does nothing – RiggsFolly Sep 21 '18 at 21:59
  • I'm editing my post for clarification on that. – Kari Sep 21 '18 at 22:00
  • Lord knows who upvoted this question. Its unfortunately just a whole bunch of errors – RiggsFolly Sep 21 '18 at 22:01
  • @Kari everything is wrong, your html and php script codes. Thats not how its done – Dean Sep 21 '18 at 22:02
  • @RiggsFolly Yes, but I'm just learning so I'm trying to make sure I know what every piece is so I can troubleshoot it quickly. – Kari Sep 21 '18 at 22:02
  • That is commendable, but SO is not a tutorial site – RiggsFolly Sep 21 '18 at 22:03
  • @RiggsFolly the ` – Kari Sep 21 '18 at 22:04
  • `type="radio"` all `checked` why? this means the user has will not choose. – Dean Sep 21 '18 at 22:05
  • 1
    I understand, this is my first week coding PHP and I can tell that I have a long road ahead of me. All of your comments have been incredibly helpful, thank you! I can see which fundamental errors I made that I was not privy to before. Definitely a good learning experience – Kari Sep 22 '18 at 06:56
  • 1
    Not sure why this was flagged as either typo or not able to reproduce. Encapsulating form elements in two separate forms does not appear to be a typo, rather a lack of understanding of how forms work. There may have been other typos but this is clearly the main problem and can be reproduced. It's a valid attempt regardless of how elementary the concepts may be to an experienced developer. – wheelmaker Sep 23 '18 at 19:11

1 Answers1

0

You should only have one form and choose either GET or POST but not both.

<form action="formhandle.php" method="post">
    First Name: <input type="text" name="firstname"><br>
    Last Name: <input type="text" name="lastname" />
    <p>Please select your classification for the upcoming fall semester:
<br /> <br />
    <input type="radio" name="class" value="F" checked="checked" /> Freshman
    <input type="radio" name="class" value="SO" checked="checked" /> Sophomore
    <input type="radio" name="class" value="J" checked="checked" /> Junior
    <input type="radio" name="class" value="SR" checked="checked" /> Senior
    <input type="submit">
    </p>
</form> 

and then:

<?php $fn = $_POST["firstname"]; ?>

Thank you for registering, <?php echo $fn ; ?>  <br>

<?php $ln = $_POST["lastname"]; ?>
<?php echo $ln ; ?> 

Your Summary is as follows: <br>
<br>
<?php
    $_POST["class"]; 
     echo "Class:";
    echo "<br>";
    echo $_POST["class"]; 
?>
wheelmaker
  • 2,605
  • 1
  • 17
  • 31