Jump to content


Photo

POSTing Email in a form - Undefined index


  • Please log in to reply
3 replies to this topic

#1 rocky48

rocky48
  • Members
  • PipPipPip
  • Advanced Member
  • 196 posts
  • LocationHastings, UK
  • Age:69

Posted 26 March 2018 - 04:28 PM

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>&nbsp;
    <input type="text" name="firstname" id="firstname" value="firstname" size="20" maxlength="20"/></p>
    <p><label for= "surname"> <b>Enter Surname: </b></label>&nbsp;
    <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>&nbsp;
    <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>&nbsp;
    <input type="text" name="road" id="road" value="road" size="30" maxlength="80"/> </p>
        <p><label for="town"> <b>Enter Town:</b> </label>&nbsp;
    <input type="text" name="town" id="town" value="town" size="30" maxlength="80"/> </p>
        <p><label for="county"> <b>Enter County:</b></label>&nbsp;
    <input type="text" name="county" id="county" value="county" size="30" maxlength="80" /> </p>
        <p><label for= "pcode"> <b>Enter Post Code:</b></label>&nbsp;
    <input type="text" name="pcode" id="pcode" value="pcode" size="30" maxlength="80" /> </p>
        <p><label for="phone"> <b>Enter Phone No:</b></label>&nbsp;
    <input type="tel" name="phone" id="phone" value="phone" size="30" maxlength="80" /> </p>
        <p><label for="mobile"> <b>Enter Mobile No:</b></label>&nbsp;
    <input type="tel" name="mobile" id="mobile" value="mobile" size="30" maxlength="80" /> </p>
        <p><label for="email"> <b>Enter Email:</b></label>&nbsp;
    <input id="email" type="text"></p>
        <p><label for="date"><b>Enter Date of Birth:</b></label>&nbsp;
    <input id="date" type="date"> </p>
         </fieldset>
    <fieldset>
    <p><label><b>Do you wish that the club obtains your BMFA membership & Insurance:  &nbsp;</b></label>&nbsp;(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:  &nbsp;</b></label>&nbsp;(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:  &nbsp;</b></label>&nbsp;(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:  &nbsp;</b></label>&nbsp;(click on box to see the list)
        <SELECT name= "subs_amount">
            <option value="0">0</option>
            <option value="10.00">&pound;10.00</option>
            <option value="13.00">&pound;13.00</option>
            <option value="15.00">&pound;15.00</option>
            <option value="17.00">&pound;17.00</option>
            <option value="24.00">&pound;24.00</option>
            <option value="27.00">&pound;27.00</option>
            <option value="34.00">&pound;34.00</option>
            <option value="44.00">&pound;44.00</option>
        </SELECT><br><br>
        <b>Description of Fees</b><br><br>
        Social or Country members &nbsp;&pound;10<br>
        Family Junior member &nbsp;&pound;13<br>
        Junior Country member &nbsp;&pound;17<br>
        Family Partner member &nbsp;&pound;24<br>
        Junior Club member  (Includes BMFA fees)&nbsp;&pound;27<br>
        Family Senior member &nbsp;&amp;&pound;34<br>
        Senior Club member (Includes BMFA fees) &nbsp;&pound;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 (&pound;10).
    </p>
        </fieldset>        
        <fieldset><legend><b>Please select the method of payment</b></legend>
        <p><label><b>Payment Method:  &nbsp;</b></label>&nbsp;(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?


Rocky48

#2 dalecosp

dalecosp
  • Members
  • PipPipPip
  • Advanced Member
  • 446 posts
  • LocationMissouri

Posted 26 March 2018 - 04:30 PM

<input id="email"> also needs a name attribute. ;)   Perhaps more coffee?


Edited by dalecosp, 26 March 2018 - 04:31 PM.

"God doesn't play dice" --- Albert Einstein
"Perl is hardly a paragon of beautiful syntax." --- Weedpacket

#3 requinix

requinix
  • Administrators
  • Impoverished Administrator
  • 9,817 posts
  • LocationWA

Posted 26 March 2018 - 07:07 PM

Same for the date of birth.
The Reimann Zeta Function Trolley Problem | If you want to escape with me, come take my hand...

#4 cyberRobot

cyberRobot
  • Moderators
  • Much to Learn
  • 2,790 posts

Posted 27 March 2018 - 12:37 PM

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>&nbsp;
<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.mo...L/Element/label






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users