gareth886 Posted September 10, 2007 Share Posted September 10, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/68694-solved-help-with-posting-to-a-database/ Share on other sites More sharing options...
MadTechie Posted September 10, 2007 Share Posted September 10, 2007 can you post the form please (use the code tags) [code.][./code] (without the dot) Quote Link to comment https://forums.phpfreaks.com/topic/68694-solved-help-with-posting-to-a-database/#findComment-345315 Share on other sites More sharing options...
Ninjakreborn Posted September 10, 2007 Share Posted September 10, 2007 You just grab the post value of the checkbox the same you would anything (unless the form is get then you use get). Quote Link to comment https://forums.phpfreaks.com/topic/68694-solved-help-with-posting-to-a-database/#findComment-345327 Share on other sites More sharing options...
gareth886 Posted September 10, 2007 Author Share Posted September 10, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/68694-solved-help-with-posting-to-a-database/#findComment-345329 Share on other sites More sharing options...
Ninjakreborn Posted September 10, 2007 Share Posted September 10, 2007 Just grab request 1 2 and 3. <?php $request2 = $_POST['request2']; ?> Just as an example. Then just database it like you would a normal field. Quote Link to comment https://forums.phpfreaks.com/topic/68694-solved-help-with-posting-to-a-database/#findComment-345331 Share on other sites More sharing options...
gareth886 Posted September 10, 2007 Author Share Posted September 10, 2007 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; Quote Link to comment https://forums.phpfreaks.com/topic/68694-solved-help-with-posting-to-a-database/#findComment-345343 Share on other sites More sharing options...
MadTechie Posted September 10, 2007 Share Posted September 10, 2007 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']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/68694-solved-help-with-posting-to-a-database/#findComment-345350 Share on other sites More sharing options...
gareth886 Posted September 10, 2007 Author Share Posted September 10, 2007 Excellent, thats sorted it. As you may be able to tell, I'm still in the process of teaching myself PHP. Many thanks for your help. Gareth Quote Link to comment https://forums.phpfreaks.com/topic/68694-solved-help-with-posting-to-a-database/#findComment-345372 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.