Ok, I am very new at php coding but I thought I would give it a shot. I am building a site for a friend of mine for his video game team. The problem I am having is they want an application form so I made the form but I can not get the php script to enter the data from the form. I used a couple tutorials and I cannot find the problem at all so I thought I would try here. I am using dreamweaver for this and this is the php coding I have.

<?php

/*subject and email*/

    $emailSubject = 'mBz Application!' ;
    $webMaster = 'raulozzi1@gmail.com';

/*gathering data variables*/

    $gtField = $_post['gt'];
    $micField = $_post['mic'];
    $membershipField = $_post['membership'];
    $playField = $_post['play'];
    $ageField = $_post['age'];
    $kdField = $_post['kd'];
    $gamesField = $_post['games'];

    $body = <<<EOD
<br><hr><br>
Gamgertag: $gt <br>
Microphone: $micField <br>
Membership: $membership <br>
Play: $play <br>
Age :$age <br>
KD: $kd <br>
Games: $games <br>

EOD;

    $headers = "From: $gt\r\n";
    $headers .= "content-type: text/html\r\n";
    $success = mail($webMaster, $emailSubject, $body, $headers);

I also have the ending (where it redirects to another page upon submission) but that is working correctly and the entire page is closed with ?> Can you see a problem? all of the names are correct as well as none of the id's in the html page are capital. All that I get in the email when the page is submited is
Gamertag:
Microphone:
Membership:
Play:
Age:
KD:
Games:

thats it, nothing is entered. Any help?

Also the form is located at idroidrandp.com/application. I am still working on it, that is why it is not on its own domain yet so please be gentle this is only my first website. I am also hosting with godaddy and have tried IE and Firefox if that helps at all.

Recommended Answers

All 6 Replies

Assuming your form has the names right from the HTML submitting page...

try capitalizing POST so $_POST['gt']

Im pretty sure globals are case sensitive.

That got me a little closer. I know get the following email sent to me from the form.
Gamgertag:
Microphone: Yes
Membership:
Play:
Age :
KD:
Games:

so the mirophone field is populating in the form submission. I looked at the microphone field in the html and didn't see anything different. Here is the code for the form.

<body>

<div class="container">
  <div class="content"><!-- end .content -->
    <form id="form1" name="form1" method="post" action="applicationsubmit.php">
      <div align="center">
        <p>&nbsp;</p>
        <p>
          <label for="gt">Xbox Live gamertag</label>
          <input type="text" name="gt" id="gt" />
        </p>
        <p>
          <label for="mic">Do you have a microphone</label>
          <select name="mic" size="1" id="mic">
            <option value="Yes">Yes</option>
            <option value="No">No</option>
          </select>
        </p>
        <p>
          <label for="membership">Do you have a Premium Elite membership</label>
          <select name="membership" size="1" id="membership">
            <option value="Yes">Yes</option>
            <option value="No">No</option>
          </select>
        </p>
        <p>
          <label for="play">Will you participate in Clan Ops and Challenges</label>
          <select name="play" size="1" id="play">
            <option value="Yes">Yes</option>
            <option value="No">No</option>
          </select>
        </p>
        <p>
          <label for="age">Are you over 17</label>
          <select name="age" size="1" id="age">
            <option value="Yes">Yes</option>
            <option value="No">No</option>
          </select>
        </p>
        <p>
          <label for="kd">What is your K/D ratio</label>
          <input name="kd" type="text" id="kd" />
        </p>

        <p>
          <label>
            <input type="radio" name="What game modes do you play" value="tdm" id="games" />
            Team Deathmatch</label>
          <br />
          <label>
            <input type="radio" name="What game modes do you play" value="KC" id="games" />
            Kill Confirmed</label>
          <br />
          <label>
            <input type="radio" name="What game modes do you play" value="Defender" id="games" />
            Team Defender</label>
          <br />
          <label>
            <input type="radio" name="What game modes do you play" value="Domintion" id="games" />
            Domination</label>
          <br />
          <label>
            <input type="radio" name="What game modes do you play" value="Demo" id="games" />
            Demolition</label>
          <br />
          <label>
            <input type="radio" name="What game modes do you play" value="S&D" id="games" />
            Search & Destroy</label>
          <br />
          <label>
            <input type="radio" name="What game modes do you play" value="CTF" id="games" />
            Capture the Flag</label>
          <br />
          <label>
            <input type="radio" name="What game modes do you play" value="Tactical" id="games" />
            Team Tactical</label>
          <br />
        </p>
        <p>
          <INPUT TYPE="image" SRC="submit.png" HEIGHT="80" WIDTH="180" BORDER="0" ALT="Submit Form">
          <br />
        </p>
      </div>
    </form>

any other ideas? And the whole section that says what game modes do you play is a radio group section, is this setup correctly?

Line 22: $membershipField (as per your assigned variable above)
In fact.. looks like all your variables need to changed other than Mic :-P

you need to use the same variable names you assigned.

so.. like the one I pointed out -
Line 11: $micField = $_POST['mic'];
Line 22: Microphone: $micField;

However, for line 10, 20:
Line 10: $gtField = $_POST['gt'];
Line 20: Gamertag: $gt; //this is a mismatch

Good luck!

Ryan

As for your other question - I do not think that radio buttons need labels (none of them do, really, but it's fine if you use them. However, you are putting a null label in for the radios so.. they are a bit useless.).

Wow I guess some stuff has changed since the tutorial. I double check with it and they keep all the fields Membership: $membership <br> without the Field at the end. I added the one to the mic field because it wasnt working before. Thank you for the catch ryantroop.

The only issue I have now is none of the radio buttons are submitting any data and for some reason it will not allow me to select multiples either and I have no option to allow for multiple select.

Here is the code for the radio buttons.

<p>
          <label>
            <input type="radio" name="What game modes do you play" value="tdm" id="games_1" />
            Team Deathmatch</label>
          <br />
          <label>
            <input type="radio" name="What game modes do you play" value="KC" id="games_2" />
            Kill Confirmed</label>
          <br />
          <label>
            <input type="radio" name="What game modes do you play" value="Defender" id="games_3" />
            Team Defender</label>
          <br />
          <label>
            <input type="radio" name="What game modes do you play" value="Domintion" id="games_4" />
            Domination</label>
          <br />
          <label>
            <input type="radio" name="What game modes do you play" value="Demo" id="games_5" />
            Demolition</label>
          <br />
          <label>
            <input type="radio" name="What game modes do you play" value="S&D" id="games_6" />
            Search & Destroy</label>
          <br />
          <label>
            <input type="radio" name="What game modes do you play" value="CTF" id="games_7" />
            Capture the Flag</label>
          <br />
          <label>
            <input type="radio" name="What game modes do you play" value="Tactical" id="games_8" />
            Team Tactical</label>
        </p>

I changed all the id's to include _1, _2, _3 etc. because it was not working without them. I made sure to change the php form to look for that id as well and still nothing is populating.

    $gtField = $_POST['gt'];
    $micField = $_POST['mic'];
    $membershipField = $_POST['membership'];
    $playField = $_POST['play'];
    $ageField = $_POST['age'];
    $kdField = $_POST['kd'];
    $games_1Field = $_POST['games_1'];
    $gamesField = $_POST['games_2'];
    $gamesField = $_POST['games_3'];
    $gamesField = $_POST['games_4'];
    $gamesField = $_POST['games_5'];
    $gamesField = $_POST['games_6'];
    $gamesField = $_POST['games_7'];
    $gamesField = $_POST['games_8'];

    $body = <<<EOD
<br><hr><br>
Gamgertag: $gtField <br>
Microphone: $micField <br>
Membership: $membershipField <br>
Play: $playField <br>
Age :$ageField <br>
KD: $kdField <br>
Games: $games_1Field <br>

I know that most of this doesnt match on the php form, but I did them a couple different ways to test and see which would work. As you see I have $games_1Field = $_POST['games_1'] and then for the email it has Games:: $games_1Field and it still isn't working. Any ideas?

I think what you want is a checkbox, not a radio button. Only 1 radio may be picked per form, per name (Right now, all of your radios have the name "What game modes do you play"

If you change those to check boxes you can pick multiples, and they will end up stored in an array (this makes a 2 dimensional array within POST. Ill explain).

So, lets just make a 2 checkbox form, and how to handle it.

<form action='myphp.php' method='post'>
<input type='checkbox' name='myvariable[]' value='A' />My Label A<br />
<input type='checkbox' name='myvariable[]' value='B' />My Label B<br />
<input type='submit' value='Send'>
</form>

Notice the [] after the name.


Lets say I do 3 attempts with this script.
attempt 1: no boxes checked
attempt 2: only Value A is checked
attempt 3: Both are checked.

Attempt 1:
$_POST['myvariable'] is unset. There are no values, and it cannot be accessed.

Attempt 2:
$_POST['myvariable'] == 'A' <- the only option selected. This may or may not work.
Alternatively, we can do:
$_POST['myvariable'][0] == 'A' as this is still a 2 dimensional array. Same way of calling it, but more direct, and in our case more "proper."

Attempt 3:
$_POST['myvariable'] will result in "Array" because it has an array stored at it's location. We have a 2 dimensional array and need to treat it as such.

$_POST['myvariable'][0] == 'A'
$_POST['myvariable'][1] == 'B'


So, how do we use this information?

In your case, you want people to show what kinds of games they play, store it in a nice human readable fashion, and send it along in an email.... so...

$lettersIwant = 'Games picked: '; //provide empty string in case there are no values;

$lettersIwant .= join(', ', $_POST['myvariable']);   /*basically makes a string separated by a comma and a white space. We use .= to tell the interpreter that we want to "add to the string" what comes next, and not overwrite the variable.*/

If you have any other questions, let me know! :)

ugh, sorry.. use implode(', ', $_POST['myvariabel']);

join is depreciated.

And so youre clear on what will be happening, when you are all done with that you will end up with the string:

Games picked: A, B

and that string would have been stored in $lettersIwant

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.