Jump to content

Recommended Posts

I am designing a form where the users input information to be stored on a database.

All of the other inputs apart from the email post OK, but the email does not!

The error is: Notice: Undefined index: email in /home/hp3-linc4-nfs2-y/555/1099555/user/htdocs/includes/renew1.php on line 19

Consequently the mysqli query does not succeed.

Here is the section of code in the html file:

<h1>Online Renewal Form</h1>
<form action="includes/renew1.php" method="post">
    <fieldset>
    
    <p><label for= "firstname"><b>Enter Firstname:</b></label> 
    <input type="text" name="firstname" id="firstname" value="firstname" size="20" maxlength="20"/></p>
    <p><label for= "surname"> <b>Enter Surname: </b></label> 
    <input type="text" name="surname" id="surname" value="surname" size="20" maxlength="40"/></p>
    <p><label for= "bmfa_no"> <b>Enter BMFA No:</b></label> 
    <input type="text" name="bmfa_no" id="bmfa_no" value="BMFA_No" size="30" maxlength="80" /> </p>
    <p><label for= "road"> <b>Enter Road:</b></label> 
    <input type="text" name="road" id="road" value="road" size="30" maxlength="80"/> </p>
        <p><label for="town"> <b>Enter Town:</b> </label> 
    <input type="text" name="town" id="town" value="town" size="30" maxlength="80"/> </p>
        <p><label for="county"> <b>Enter County:</b></label> 
    <input type="text" name="county" id="county" value="county" size="30" maxlength="80" /> </p>
        <p><label for= "pcode"> <b>Enter Post Code:</b></label> 
    <input type="text" name="pcode" id="pcode" value="pcode" size="30" maxlength="80" /> </p>
        <p><label for="phone"> <b>Enter Phone No:</b></label> 
    <input type="tel" name="phone" id="phone" value="phone" size="30" maxlength="80" /> </p>
        <p><label for="mobile"> <b>Enter Mobile No:</b></label> 
    <input type="tel" name="mobile" id="mobile" value="mobile" size="30" maxlength="80" /> </p>
        <p><label for="email"> <b>Enter Email:</b></label> 
    <input id="email" type="text"></p>
        <p><label for="date"><b>Enter Date of Birth:</b></label> 
    <input id="date" type="date"> </p>
         </fieldset>
    <fieldset>
    <p><label><b>Do you wish that the club obtains your BMFA membership & Insurance:   </b></label> (click on box to see the list)
    <SELECT name= "club_mem">
        <option value="No">NO</option>
        <option value="Yes">YES</option>
        </SELECT><br><br>    
     </fieldset>
    <fieldset>
    <p><label><b>Country Member:   </b></label> (click on box to see the list)
    <SELECT name= "country_mem">
        <option value="No">NO</option>
        <option value="Yes">YES</option>
        </SELECT><br><br>    
     </fieldset>
    <fieldset>
    <p><label><b>Do you require training:   </b></label> (click on box to see the list)
    <SELECT name= "train">
        <option value="No">NO</option>
        <option value="Yes">YES</option>
        </SELECT><br><br>    
     </fieldset>
    <fieldset><legend><b>The Amount to Pay</b></legend>
    <p><label><b>Membership Fees:   </b></label> (click on box to see the list)
        <SELECT name= "subs_amount">
            <option value="0">0</option>
            <option value="10.00">£10.00</option>
            <option value="13.00">£13.00</option>
            <option value="15.00">£15.00</option>
            <option value="17.00">£17.00</option>
            <option value="24.00">£24.00</option>
            <option value="27.00">£27.00</option>
            <option value="34.00">£34.00</option>
            <option value="44.00">£44.00</option>
        </SELECT><br><br>
        <b>Description of Fees</b><br><br>
        Social or Country members  £10<br>
        Family Junior member  £13<br>
        Junior Country member  £17<br>
        Family Partner member  £24<br>
        Junior Club member  (Includes BMFA fees) £27<br>
        Family Senior member  &£34<br>
        Senior Club member (Includes BMFA fees)  £44<br>
        Family members must complete the renewal form if they want the club to sign them up for BMFA family membership.<br>
        If the family member has Country membership of BMFA they must enrol as a country member (£10).
    </p>
        </fieldset>        
        <fieldset><legend><b>Please select the method of payment</b></legend>
        <p><label><b>Payment Method:   </b></label> (click on box to see the list)
        <select name="pay_meth">
            <option value="Cheque">Cheque</option>
            <option value="Cash">Cash</option>
            <option value="BACS">BACS</option>
        </select>
        </fieldset>
    <br />
    <div align="left"><input type="submit" name="submit" value="Submit" /></div>
    <input type="hidden" name="submitted" value="TRUE" />

</form>   

The code in the PHP file is as follows:

 $trimmed = array_map('trim', $_POST);
        
	 $Fname = mysqli_real_escape_string($dbc, $_POST['firstname']);
	 $Sname = mysqli_real_escape_string($dbc, $_POST['surname']);
	 $Road = mysqli_real_escape_string($dbc, $_POST['road']);
	 $Town = mysqli_real_escape_string($dbc, $_POST['town']);
	 $County = mysqli_real_escape_string($dbc, $_POST['county']);
	 $Pcode = mysqli_real_escape_string($dbc, $_POST['pcode']);
	 $Phone = mysqli_real_escape_string($dbc, $_POST['phone']);
	 $Mobile = mysqli_real_escape_string($dbc, $_POST['mobile']);
	 $Email = mysqli_real_escape_string($dbc, $_POST['email']);
	 $DOB = mysqli_real_escape_string($dbc, $_POST['dob']);
	 $BMFA = mysqli_real_escape_string($dbc, $_POST['bmfa_no']);
	 $C_mem = mysqli_real_escape_string($dbc, $_POST['country_mem']);
	 $Amount = mysqli_real_escape_string($dbc, $_POST['subs_amount']);
	 $meth = mysqli_real_escape_string($dbc, $_POST['pay_meth']);
	 $club = mysqli_real_escape_string($dbc, $_POST['club_mem']);
	 $training = mysqli_real_escape_string($dbc, $_POST['train']);

I thought that the problem was in the HTML file, but I am unable to see where it is incorrect.

Please help?

Link to comment
https://forums.phpfreaks.com/topic/306948-posting-email-in-a-form-undefined-index/
Share on other sites

You could simplify the code a bit. If you enclose the input field with the <label> tag, the "id" and "for" attributes are unnecessary. For example:

<p><label><b>Enter Firstname:</b> 
<input type="text" name="firstname" value="firstname" size="20" maxlength="20"/></label></p>

More information about the <label> tag can be found here:

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label

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.