Hi peeps, I need your help I have been struggling today trying to get a form working. I have created a form where data will needs to be filled in. The results from the form will be filled in two seperate tables and these forms have checkbox and radio buttons but does not want to save it into the tables.
First it only saves the data into the first table and not the second. and second of all the data is not saved as checkboxes when I view it in mysql or the readio buttons. I have also tryed changin the type in mysql to "ENUM" but i get errors when I save it. Can someone please help me? The code what I have created is below:
<?php
if ($_POST['requestform']) { // this is saying if the submitForm button is press carry out the next if statement
if(empty($_POST['firstname']) || empty($_POST['lastname']) || empty($_POST['contract']) || empty($_POST['deptmanager']) || empty($_POST['accounttype']) || empty($_POST['mailboxlist']) || empty($_POST['outlookmail']) || empty($_POST['distributionlist']) || empty($_POST['department']) || empty($_POST['hours'])) //this code is checking if the various text boxes are empty if they are print error message
{
echo 'You Must Enter All fields to submit request';
echo '<br> ';
echo '<br> ';
if (isset($HTTP_REFERER)) {echo "<a href='$HTTP_REFERER'>BACK</a>"; } //this is php coding to create a hyperlink back button
else {echo "<a href='javascript:history.back()'>BACK</a>";
}
exit;
}
$conn = mysql_connect("localhost","root","") or die("Could Not Connect To The Database"); // this is the code for connection to the database created if cannot connect will send error message
mysql_select_db("joiners",$conn) or die("Could Not Select The Database");
{
$sql = "INSERT INTO joinrequest (account_type,email_account,phone_login,telephone_ext,desktop,laptop,token,mob ilephone,deskphone,blackberry,usbkey) VALUES ('','".$_POST['accounttype']."','".$_POST['phonelogin']."','".$_POST['telext']."','".$_POST['desktop']."','".$_POST['laptop']."','".$_POST['token']."','".$_POST['mobilephone']."','".$_POST['deskphone']."','".$_POST['blackberry']."','".$_POST['usbkey']."')"; //this part of the code runs the SQL Query of Inserting all the data gathered by each of the text boxes into each of the chosen attributes respectively
$query = mysql_query($sql,$conn) or die(mysql_error("Could Not Write Information To The Database"));
if (mysql_affected_rows($conn) == 0) {
echo 'This Client Was Not Added.';
} else {
echo 'This Client Was Added Successfully';// if everything was successfully completed it will print this message if not it will print the error message above
}
}
{
$sql1 = "INSERT INTO user (first_name,last_name,join_date,department,contract,hours,dept_manager,mailbox _list,distribution_list,hardware,software) VALUES ('','".$_POST['firstname']."','".$_POST['lastname']."','".$_POST['joindate']."','".$_POST['department']."','".$_POST['contract']."','".$_POST['hours']."','".$_POST['deptmanager']."','".$_POST['mailboxlist']."','".$_POST['distributionlist']."','".$_POST['hardware']."','".$_POST['software']."',)"; //this part of the code runs the SQL Query of Inserting all the data gathered by each of the text boxes into each of the chosen attributes respectively
$query1 = mysql_query($sql1,$conn) or die(mysql_error("Could Not Write Information To The Database"));
if (mysql_affected_rows($conn) == 0) {
echo 'This Client Was Not Added.';
} else {
echo 'This Client Was Added Successfully';// if everything was successfully completed it will print this message if not it will print the error message above
}
}
}
?>
<br>
<font color="#003399" face="Geneva, Arial, Helvetica, sans-serif"><strong>Employee
Information</strong></font><br>
<font face="Geneva, Arial, Helvetica, sans-serif">First Name:
<input type="text" name="firstname">
<br>
Date(yyyy/mm/dd):
<input type="text" name="joindate">
</font><br>
<label><font face="Geneva, Arial, Helvetica, sans-serif">Permanent
<input type="radio" name="contract" value="Permanent">
</font></label>
<font face="Geneva, Arial, Helvetica, sans-serif">
<label> Contract
<input type="radio" name="contract" value="Contract">
</label>
</font><font face="Geneva, Arial, Helvetica, sans-serif"><br>
Department Manager:
<input type="text" name="deptmanager">
<br>
<br>
</font><font color="#003399" face="Geneva, Arial, Helvetica, sans-serif"><strong>Request<br>
</strong></font>
<label> <font face="Geneva, Arial, Helvetica, sans-serif"> New Account</font></label>
<font face="Geneva, Arial, Helvetica, sans-serif"></font>
<label><font face="Geneva, Arial, Helvetica, sans-serif">
<input type="radio" name="accounttype" value="New">
</font></label>
<font face="Geneva, Arial, Helvetica, sans-serif">
<label> Current Account</label>
<label>
<input type="radio" name="accounttype" value="Current">
</label>
</font><font face="Geneva, Arial, Helvetica, sans-serif"><br>
MailBox Listbr>
<textarea name="mailboxlist" cols="40" rows="5"></textarea>
</font><font face="Geneva, Arial, Helvetica, sans-serif"><br>
Outlook Mail:
<input type="checkbox" name="outlookmail" value="checkbox">
<br>
Distribution Listbr>
<textarea name="distributionlist" cols="40" rows="5">Landmark House</textarea>
<br>
Phone Login:
<input type="checkbox" name="phonelogin" value="checkbox">
<br>
Telephone Ext:
<input type="checkbox" name="telext" value="checkbox">
</font><br>
<br>
</p>
</td>
<td width="370" valign="top"><p><br>
</p>
<p><font face="Geneva, Arial, Helvetica, sans-serif">Last Name:
<input type="text" name="lastname">
<br>
Department:
<input type="text" name="department">
<br>
</font>
<label> <font face="Geneva, Arial, Helvetica, sans-serif"> Temporary</font></label>
<font face="Geneva, Arial, Helvetica, sans-serif"></font>
<label><font face="Geneva, Arial, Helvetica, sans-serif">
<input type="radio" name="hours" value="Temporary">
</font></label>
<font face="Geneva, Arial, Helvetica, sans-serif">
<label> </label>
Flexibility
<label>
<input type="radio" name="hours" value="Flexibility">
</label>
<label> </label>
Part Time
<label>
<input type="radio" name="hours" value="PartTime">
</label>
</font><br>
<br>
</p></td>
<td> </td>
</tr>
<tr>
<td height="80" rowspan="3" bgcolor="dcdcdc"> </td>
<td rowspan="3" bgcolor="003399"> </td>
<td rowspan="3"> </td>
<td height="164" valign="top">
<p><font color="#003399" face="Geneva, Arial, Helvetica, sans-serif"><strong>Hardware
Request </strong></font><font face="Geneva, Arial, Helvetica, sans-serif"><br>
Desktop:
<input type="checkbox" name="desktop" value="checkbox">
<br>
Laptop:
<input type="checkbox" name="laptop" value="checkbox">
<br>
Token:
<input type="checkbox" name="token" value="checkbox">
<br>
Mobile Phone</font>: <font face="Geneva, Arial, Helvetica, sans-serif">
<input type="checkbox" name="mobilephone" value="checkbox">
</font><br>
<font face="Geneva, Arial, Helvetica, sans-serif">Desk Phone:
<input type="checkbox" name="deskphone" value="checkbox">
<br>
Blakcberry</font>: <font face="Geneva, Arial, Helvetica, sans-serif">
<input type="checkbox" name="blackberry" value="checkbox">
</font><br>
<font face="Geneva, Arial, Helvetica, sans-serif">USB Key:
<input type="checkbox" name="usbkey" value="checkbox">
<br>
</font> </p></td>
<td valign="top"> <p><font color="#003399" face="Geneva, Arial, Helvetica, sans-serif"><strong>
Software Request</strong></font><br>
<font face="Geneva, Arial, Helvetica, sans-serif"><strong>Default System
contains/strong><br>
MS Office 2003, CASE, Adobe Reader, PDF Writer, Visio Viewer, AL Zip (WinZip),
WINIS/SPIN and Right fax.<br>
</font></p></td>
<td rowspan="3"> </td>
</tr>
<tr>
<td height="193" valign="top"> <p><font face="Geneva, Arial, Helvetica, sans-serif">
Other please specify/font><br>
<font face="Geneva, Arial, Helvetica, sans-serif">
<textarea name="hardware" cols="40" rows="5"></textarea>
</font></p>
<p><font face="Geneva, Arial, Helvetica, sans-serif"> </font></p>
<p><font face="Geneva, Arial, Helvetica, sans-serif"></font></p></td>
<td valign="top"><font face="Geneva, Arial, Helvetica, sans-serif">Other please
specifybr>
<textarea name="software" cols="40" rows="5"></textarea>
</font></td>
</tr>
<tr>
<td height="88" colspan="2"><div align="center">
<input type="submit" name="requestform" value="Request">
</div></td>
</tr>
<tr>
<td height="19" bgcolor="003399"> </td>
<td bgcolor="003399"> </td>
<td bgcolor="003399"> </td>
<td colspan="2" bgcolor="003399"> </td>
<td bgcolor="003399"> </td>
</tr>
</table>
</form>
</body>
</html>