Jump to content

Recommended Posts

I'm wondering if anyone here can help me.  I'm currently developing a website that includes an online registration form using PHP.  I'm having trouble getting the script to post the value of a check box to the database.  I have succesfully managed to post the values of the text boxes to the database but can't figure out how to post the value of the check boxes.

 

Any help is much appreciated.

Link to comment
https://forums.phpfreaks.com/topic/68694-solved-help-with-posting-to-a-database/
Share on other sites

The code is attached below.  Its only the check box values that I am having trouble with posting to the database. The rest works fine.

 

Thanks for any help.

 

<form action="*****" method="post" id="mainform" onsubmit="validate();">
           <p>
             <input name="subject" type="hidden" value="Conference Booking" />
             <input 
name="realname" type="hidden" value="Conference 2007 Booking" />
             <input name="template" 
type="hidden" id="template" value="emailtemplate18.htm" />
             <input 
name="html" type="hidden" id="html" 
value="yes" />
             <input name="Event_Title" type="hidden" id="Event_Title" value="Conference 2007" />
             <input name="Event_Date" type="hidden" id="Event_Date" value="Date" />
             <input name="Event_Venue" type="hidden" id="Event_Venue" value="Venue" />
             <input name="Pic" type="hidden" id="Pic" value="../img/xxx.gif" />
             <input name="Check" type="hidden" id="Check" value="1" />
           </p>
           <table width="100%" border="0" cellspacing="2" summary="Date Venue Info">
             <tr>
               <td colspan="3" valign="top">

               </td>
             </tr>
             <tr>
               <td colspan="3"><p class="topic"><b>Please Fill 
                 in your details below:<br />
                                           <br />
               </b></p></td>
             </tr>
             <tr>
               <td height="30" colspan="3" valign="top"><table width="100%" border="0" cellpadding="2" cellspacing="0" bgcolor="#F0EADA" style="border:1px solid #cccccc;" summary="User Input">
                   <tr valign="top">
                     <td width="18%" style="padding-top:6px;"><p  class="topic">I wish to:</p></td>
                     <td width="82%"><p  class="topic">
                       <label>
                       <input type="checkbox" name="Request" value="Attend Main Conference" />
                       Attend the <strong>Main Conference</strong><br />
                       <input type="checkbox" name="Request2" value="Attend Conference Dinner" />
                       Attend the <strong>Conference Dinner</strong><br />
                       <input type="checkbox" name="Request3" value="Attend Post Conference Workshop" />
                       Attend the <strong>Post-Conference </strong></label>
                       <strong>Workshop</strong></p>
                     <p  class="topic"> </p></td>
                   </tr>
               </table></td>
             </tr>
             <tr>
               <td width="18%"> </td>
               <td align="left" class="lightblue"> </td>
               <td> </td>
             </tr>
             <tr>
               <td><label for="Name">Name:</label></td>
               <td width="54%" align="left" class="lightblue"><input name="Name" id="Name" type="text" size="38" />                </td>
               <td width="28%"><font size="1">Required</font></td>
             </tr>
             <tr>
               <td><label for="Position">Position:</label></td>
               <td align="left" valign="top" class="lightblue" ><input name="Position" type="text" id="Position" size="38" />                </td>
               <td> </td>
             </tr>
             <tr>
               <td><label for="Company">Organisation:</label></td>
               <td align="left" valign="top" class="lightblue"><input name="Company" type="text" id="Company" size="38" />                </td>
               <td><font size="1">Required</font></td>
             </tr>
             <tr>
               <td valign="top"><label for="Address">Address:</label></td>
               <td align="left" valign="top" class="lightblue" ><textarea cols="29" rows="5" name="Address" id="Address"></textarea>                </td>
               <td><font size="1">Required</font></td>
             </tr>
             <tr>
               <td><label for="Telephone">Telephone:</label></td>
               <td align="left" valign="top" class="lightblue" ><input name="Telephone" type="text" id="Telephone" size="38" />                </td>
               <td><font size="1">Required</font></td>
             </tr>
             <tr>
               <td><label for="fax">Fax:</label></td>
               <td align="left" valign="top" class="lightblue" ><input name="Fax" type="text" id="Fax" size="38" />                </td>
               <td> </td>
             </tr>
             <tr>
               <td><label for="mailfrom">Email:</label></td>
               <td align="left" class="lightblue" ><input name="mailfrom" type="text" id="mailfrom" size="38" />                </td>
               <td><font size="1">Required</font></td>
             </tr>

             <tr>
               <td height="36" valign="top" class="lightblue"><label for="comments">Comments?</label></td>
               <td height="36" valign="middle" class="lightblue"><textarea name="comments" cols="29" rows="3" id="comments"></textarea></td>
               <td height="36" valign="top" class="lightblue">(optional)</td>
             </tr>
             <tr>
               <td height="36" valign="top" class="lightblue"><br />
                   <br />
                   <br />
                   <br />
                   <br /></td>
               <td height="36" colspan="2" valign="middle" class="lightblue"><input type="submit" value="Submit Your Order" name="B1" />
                   <span class="smallgreen"><font size="1"><-- 
                     Click here to complete your Registration</font></span></td>
             </tr>
             </table>
         </form>

As far as I'm aware I am grabbing these the same way as the rest of the fields but it doesnt seem to be grabbing the values of Request, Request2 and Request3 when the box is checked.  These fields in the database apear empty.  The code below is when they have been grabbed:

$event = $_POST['Event_Title'];
$Event_Date = $_POST['Event_Date'];
$Event_Venue = $_POST['Event_Venue'];
$Request = $_POST['Request'];
$Request2 = $_POST['Request2'];
$Request3 = $_POST['Request3'];
$Name1 = $_POST['Name'];
$Job1 = $_POST['Position'];
$Company = $_POST['Company'];
$Address = $_POST['Address'];
$Telephone = $_POST['Telephone'];
$Fax = $_POST['Fax'];
$Mailfrom = $_POST['mailfrom'];
$Comments = $_POST['comments'];
$IP = $REMOTE_ADDR;

 

you can use isset, to find if its been checked

 

<form method="post">
<input name="test1" type="checkbox" value="111" />
<input name="test2" type="checkbox" value="222" />
<input name="test3" type="checkbox" value="333" />
<input type="submit" />
</form>
<?php
if (isset($_POST['test1']))
{
echo $_POST['test1'];
}
if (isset($_POST['test2']))
{
echo $_POST['test2'];
}
if (isset($_POST['test3']))
{
echo $_POST['test3'];
}

?>

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.