Saving a form with text and checboxes to text file - php

I an working on a HTML form to help me keep track on information when I play roll playing games.
The form has a grid of checkboxes that are used to track health. I also have a text box that I track other stats in.
I want to have a 2 buttons: LOAD and SAVE.
When save is hit the current status (whether or not a box is marked), if every form element is saved to a text file Save/save.txt. Any information in a existing text file should be replaced. I only care about the current settings.
when load is hit the data is loaded from the text file and the form is filled out like it was when it was saved.
How do I get this form to save / load?
<form action="HP_Tracker.php" method="post">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><center><b>W</b></center></td>
<td> </td>
</tr>
<tr>
<td bgcolor="ffffff"><input name="W1" type="checkbox" value="" /></td>
<td bgcolor="000000"><input name="S24" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="ffffff"><input name="W2" type="checkbox" value="" /></td>
<td bgcolor="000000"><input name="S23" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="F0F0F5"><input name="W3" type="checkbox" value="" /></td>
<td bgcolor="0A0A0F"><input name="S22" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="E0E0EB"><input name="W4" type="checkbox" value="" /></td>
<td bgcolor="14141F"><input name="S21" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="D1D1E0"><input name="W5" type="checkbox" value="" /></td>
<td bgcolor="1F1F2E"><input name="S20" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="C2C2D6"><input name="W6" type="checkbox" value="" /></td>
<td bgcolor="29293D"><input name="S19" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="B2B2CC"><input name="W7" type="checkbox" value="" /></td>
<td bgcolor="33334C"><input name="S18" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="A3A3C2"><input name="W8" type="checkbox" value="" /></td>
<td bgcolor="3D3D5C"><input name="S17" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="9494B8"><input name="W9" type="checkbox" value="" /></td>
<td bgcolor="47476B"><input name="S16" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="8585AD"><input name="W10" type="checkbox" value="" /></td>
<td bgcolor="52527A"><input name="S15" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="7575A3"><input name="W11" type="checkbox" value="" /></td>
<td bgcolor="5C5C8A"><input name="S14" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="666699"><input name="W12" type="checkbox" value="" /></td>
<td bgcolor="666699"><input name="S13" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="5C5C8A"><input name="W13" type="checkbox" value="" /></td>
<td bgcolor="7575A3"><input name="S12" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="52527A"><input name="W14" type="checkbox" value="" /></td>
<td bgcolor="8585AD"><input name="S11" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="47476B"><input name="W15" type="checkbox" value="" /></td>
<td bgcolor="9494B8"><input name="S10" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="3D3D5C"><input name="W16" type="checkbox" value="" /></td>
<td bgcolor="A3A3C2"><input name="S9" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="33334C"><input name="W17" type="checkbox" value="" /></td>
<td bgcolor="B2B2CC"><input name="S8" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="29293D"><input name="W18" type="checkbox" value="" /></td>
<td bgcolor="C2C2D6"><input name="S7" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="1F1F2E"><input name="W19" type="checkbox" value="" /></td>
<td bgcolor="D1D1E0"><input name="S6" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="14141F"><input name="W20" type="checkbox" value="" /></td>
<td bgcolor="E0E0EB"><input name="S5" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="0A0A0F"><input name="W21" type="checkbox" value="" /></td>
<td bgcolor="F0F0F5"><input name="S4" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="000000"><input name="W22" type="checkbox" value="" /></td>
<td bgcolor="FFFFFF"><input name="S3" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="000000"><input name="W23" type="checkbox" value="" /></td>
<td bgcolor="FFFFFF"><input name="S2" type="checkbox" value="" /></td>
</tr>
<tr>
<td bgcolor="000000"><input name="W24" type="checkbox" value="" /></td>
<td bgcolor="FFFFFF"><input name="S1" type="checkbox" value="" /></td>
</tr>
<tr>
<td> </td>
<td><center><b>S</b></center></td>
</tr>
</table>
<hr />
Initiative<br />
<input name="Initiative" type="text" size="4" />
<br /><br />
<input name="Save" type="submit" value="SAVE" />
</form>

Try that:
<?php
if (!empty($_POST)) {
$data = implode(',', $_POST);
$fileName = 'yourFile.txt';
$file = fopen($fileName, 'a+');
fwrite($file, $data);
fclose($file);
chmod(0777);
}

Related

Pass variable from form to next page and put in sql statment php

Here is what I am trying to do. I have a dropdown (and or excel type look) that I need to pull data from the database. When I have an item selected I need to pass the info to the next page via a session. I have the drop down pulling from the database but I need to list Name and address in the dropdown.
If this is not possible I can do a list of items from a search but I will need to make the id a link to pass the id to the next page where I need to build a report.
If you can give me some info on this I would appreciate it.
Here is what I have for code on the dropdown
Code: Select all
<?php
// declare database connection variables.
$host = "localhost";
$username = "root";
$password = "";
$db_name = "sample";
$tbl_name = "tbl_report";
// connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql = "SELECT id, name, address FROM $tbl_name";
$result = mysql_query($sql) or die(mysql_error());
$dropdown = "<form action='report.php' method='post'>";
$dropdown .= "<select name='items' class='select'>";
while ($row = mysql_fetch_assoc($result)) {
$dropdown .= '<option value="' . $row['id'] . '">' .
$row['name'] . ' - ' . $row['address'] . '</option>';;
}
$dropdown .= "\r\n</select>";
$dropdown .= "<input type='submit' name='submit' value='Submit'>";
$dropdown .= "</form>"; //closing the form tag
echo $dropdown;
?>
What I need to do is pass the ID to the next page and have the $id show up in the code for my next sql statement.
Here is the code that I have for the next page sql statement.
select * from $tbl_name where id = (this is where I get hung up on.)
What I need is a way to pass the $row['id'] to the next page and put that in the sql code and then use the get method to display the info on the form of that page.
Here is the setup of the pages. select-report.php (this is where the drop down is) --> report.php.
Here is the form for report.php where i need to carry over the value of id and do a sql of select * from $tbl_name where id=[$post=items]; Then i need to use the $get to put all the items in the form below:
<form id="form1" name="form1" method="post" action="">
<table width="100%" border="0" cellspacing="4" cellpadding="4">
<tr>
<td width="20%">Water Purveyor
<input name="water-purveyor" type="text" id="water-purveyor" size="35" />
</td>
<td colspan="2">Facility Contact
<input type="text" name="facility-contact" id="facility-contact" /></td>
<td colspan="2">Facility Address
<input type="text" name="facility-address" id="facility-address" /></td>
</tr>
<tr>
<td>Manufacturer
<input type="text" name="manufacturer" id="manufacturer" /></td>
<td width="20%">State
<select name="state" id="state">
</select></td>
<td width="20%">Model #
<input name="model-num" type="text" id="model-num" size="10" /></td>
<td width="20%">Serial #
<input name="serial-num" type="text" id="serial-num" size="10" /></td>
<td width="20%">Meter #
<input name="meter-num" type="text" id="meter-num" size="10" /></td>
</tr>
<tr>
<td>Owner
<input type="text" name="owner" id="owner" /></td>
<td>Phone #
<input name="phone-num" type="text" id="phone-num" size="12" /></td>
<td>Caged
<input type="checkbox" name="caged" id="caged" /></td>
<td>Locked
<input type="checkbox" name="locked" id="locked" /></td>
<td>Code key
<input name="code-key" type="text" id="code-key" size="6" /></td>
</tr>
<tr>
<td colspan="2">Owner Address
<input name="owner-address" type="text" id="owner-address" size="50" /></td>
<td>Owner City
<input type="text" name="owner-city" id="owner-city" /></td>
<td>Owner State
<select name="owner-state" id="owner-state">
</select></td>
<td>Owner Zip
<input name="owner-zip" type="text" id="owner-zip" size="10" /></td>
</tr>
<tr>
<td>Contact
<input type="text" name="contact" id="contact" /></td>
<td>Contact Phone
<input name="contact-phone" type="text" id="contact-phone" size="10" /></td>
<td> </td>
<td>Other</td>
<td> </td>
</tr>
<tr>
<td colspan="2">Facility Name
<input name="facility-name" type="text" id="facility-name" size="40" /></td>
<td colspan="3">Assembly Address
<input name="assembly-address" type="text" id="assembly-address" size="75" /></td>
</tr>
<tr>
<td colspan="5">Onsite Location
<input name="onsite-location" type="text" id="onsite-location" size="75" /></td>
</tr>
<tr>
<td colspan="5">email Address
<input name="email" type="text" id="email" size="125" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>SHUTOFF VALVES</td>
<td colspan="2"><table width="100%" border="0" cellspacing="4" cellpadding="4">
<tr>
<td>N/A</td>
<td>Good</td>
<td>Poor</td>
<td>Fail</td>
</tr>
</table></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Valve 1</td>
<td colspan="2"><table width="100%" border="0" cellspacing="4" cellpadding="4">
<tr>
<td><input type="checkbox" name="v1-na" id="v1-na" /></td>
<td><input type="checkbox" name="v1-good" id="v1-good" /></td>
<td><input type="checkbox" name="v1-poor" id="v1-poor" /></td>
<td><input type="checkbox" name="v1-fail" id="v1-fail" /></td>
</tr>
</table></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Valve 2</td>
<td colspan="2"><table width="100%" border="0" cellspacing="4" cellpadding="4">
<tr>
<td><input type="checkbox" name="v2-na" id="v2-na" /></td>
<td><input type="checkbox" name="v2-good" id="v2-good" /></td>
<td><input type="checkbox" name="v2-poor" id="v2-poor" /></td>
<td><input type="checkbox" name="v2-fail" id="v2-fail" /></td>
</tr>
</table></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Assembly Replacement?
<input type="checkbox" name="assembly-replacement" id="assembly-replacement" /></td>
<td>if yes Serial #
<input type="text" name="assembly-replacement-serial" id="assembly-replacement-serial" /></td>
<td>New Installation
<input type="checkbox" name="new-install" id="new-install" /></td>
<td>Permit #
<input type="text" name="permit-num" id="permit-num" /></td>
<td> </td>
</tr>
<tr>
<td>Containment
<input type="checkbox" name="containment" id="containment" /></td>
<td>Isolation
<input type="checkbox" name="isolation" id="isolation" /></td>
<td colspan="2">Assembly Ground Clearance
<input type="text" name="assembly-ground-clearance" id="assembly-ground-clearance" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Domestic
<input type="checkbox" name="domestic" id="domestic" /></td>
<td>Irrigation
<input type="checkbox" name="irrigation" id="irrigation" /></td>
<td>Fire Line
<input type="checkbox" name="fire-line" id="fire-line" /></td>
<td>Alarmed Fire Line
<input type="checkbox" name="alarmed-fire-line" id="alarmed-fire-line" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2"><strong><em><u>Double Check Balve Assembly Repair</u></em></strong></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Repairs</td>
<td>Check Valve 1</td>
<td> </td>
<td>Check Valve 2</td>
<td> </td>
</tr>
<tr>
<td rowspan="3"> </td>
<td>Cleaned
<input type="checkbox" name="cv1-repair-cleaned" id="cv1-repair-cleaned" /></td>
<td> </td>
<td>Cleaned
<input type="checkbox" name="cv2-repair-cleaned" id="cv2-repair-cleaned" /></td>
<td> </td>
</tr>
<tr>
<td><strong>Replaced</strong></td>
<td> </td>
<td><strong>Replaced</strong></td>
<td> </td>
</tr>
<tr>
<td>Rubber Kit
<input type="checkbox" name="cv1-rubber-kit" id="cv1-rubber-kit" /></td>
<td> </td>
<td>Rubber Kit
<input type="checkbox" name="cv2-rubber-kit" id="cv2-rubber-kit" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>Other
<input type="checkbox" name="cv1-other" id="cv1-other" /></td>
<td> </td>
<td>Other
<input type="checkbox" name="cv2-other" id="cv2-other" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td colspan="2">Comments
<textarea name="cv1-other-comments" id="cv1-other-comments" cols="45" rows="5"></textarea></td>
<td colspan="2">Comments
<textarea name="cv2-other-comments" id="cv2-other-comments" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2">Initial Test By
<input name="initial-test-by" type="text" id="initial-test-by" size="50" /></td>
<td colspan="2">Certified Tester #
<input type="text" name="certified-tester-num" id="certified-tester-num" /></td>
<td>Test Date/Time
<input type="text" name="test-date-time" id="test-date-time" /></td>
</tr>
<tr>
<td>Pass
<input type="checkbox" name="initial-test-pas" id="initial-test-pas" /></td>
<td>Fail
<input type="checkbox" name="initial-test-fail" id="initial-test-fail" /></td>
<td colspan="2">Calib Expire Date
<input type="text" name="calib-expire-date" id="calib-expire-date" /></td>
<td>Guage Serial #
<input type="text" name="gague-serial-num" id="gague-serial-num" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2">Repair Test By
<input name="repair-test-by" type="text" id="repair-test-by" size="50" /></td>
<td colspan="2">Repair Date/Time
<input type="text" name="repair-date-time" id="repair-date-time" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2">Final Test by
<input name="final-test-by" type="text" id="final-test-by" size="50" /></td>
<td colspan="2">Certified Tester #
<input type="text" name="ft-certified-tester-num" id="ft-certified-tester-num" /></td>
<td>Test Date/Time
<input type="text" name="ft-date-time" id="ft-date-time" /></td>
</tr>
<tr>
<td>Pass
<input type="checkbox" name="ft-pass" id="ft-pass" /></td>
<td>Fail
<input type="checkbox" name="ft-fail" id="ft-fail" /></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="5">Comments
<textarea name="comments" id="comments" cols="80" rows="5"></textarea></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2">Video upload <input type="file" name="uploadvideo" /></td>
<td colspan="2">Image 1 <input type="file" name="uploadimage" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="2">Image 2 <input type="file" name="uploadimage2" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="2">Image 3 <input type="file" name="uploadimage3" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="2">Image 4 <input type="file" name="uploadimage4" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="2">Image 5 <input type="file" name="uploadimage5" /></td>
<td> </td>
</tr>
</table>
</form>
you can use jquery when to get the selected value like this
$("#dropdownid").change(function({ var vals = $(this).val(); })
then when you are redirecting to next page then add it as get parameter
(report.php)
if(isset($_REQUEST['submit'])){
$option = $_POST['items'];
mysql_query("SELECT * FROM `table_name` WHERE FIELD_NAME = '$options'");
}
if(isset($_REQUEST['submit'])){
$option = $_REQUEST['items'];
mysql_query("SELECT * FROM `table_name` WHERE FIELD_NAME = '$options'");
}
You can pass value to next page using php session.
$_SESSION ['name'] = $value;
and you can get value using php session from next page.
$value = $_SESSION ['name'];

how to upload photos with other detail like username, email , mobie etc

Here is my code to upload a Single Image. But i want to upload 3 images at a time.
How can i do it ?
<form enctype="multipart/form-data" action="process2.php" method="POST">
<table id="tbl1">
<tr>
<td>For Sale </td>
<td colspan="2">
<input type="hidden" name="id"/>
</td>
</tr>
<tr>
<td>Type: </td>
<td colspan="2">
<select name="type" id="slct"><option>Residential</option></select></td>
</tr>
<tr>
<td>State: </td><td colspan="2">
<select name="state" id="slct"><option>Punjab</option></select></td>
</tr>
<tr>
<td>City: </td><td colspan="2">
<select name="city" id="slct"><option>Lahore</option></select></td>
</tr>
<tr>
<td>Location: </td><td colspan="2">
<input name="location" placeholder="Enter Location Here" id="slct2" type="text" /></td>
</tr>
<tr>
<td>Bedrooms:</td><td colspan="2">
<select name="bedroom"><option>1</option></select></td>
</tr>
<tr>
<td>Land In: </td><td colspan="2">
<select name="landtype" id="slct"><option>Kanal</option></select>
</tr>
<tr>
<td>Land Area: </td><td colspan="2">
<input name="landarea" placeholder="Enter area here" id="slct2" type="text" /></td>
</tr>
<tr>
<td>Price: </td><td colspan="2">
<input name="price" placeholder="Enter price here" id="slct2" type="text" /></td>
</tr>
<tr>
<td>Photo</td>
<td ><input type="file" name="photo" id="file"/></td>
</tr>
<tr>
<td>User Details</td>
<td colspan="2">
</td>
</tr>
<tr>
<td>Name: </td><td colspan="2">
<input name="name" placeholder="full name" id="slct2" type="text" /></td>
</tr>
<tr>
<td>Mobile: </td><td colspan="2">
<input name="mobile" placeholder="format 03001234567" id="slct2" type="text" /></td>
</tr>
<tr>
<td>E-mail: </td><td colspan="2">
<input name="email" placeholder="Enter email Here" id="slct2" type="text" /></td>
</tr>
<tr>
<td></td><td colspan="2"><input type="submit" name="submit" value="Post"/></td>
</tr>
</table>
</form>
add code in HTML
<td>Photo1</td><td ><input type="file" name="photo1" id="file1"/></td>
<td>Photo2</td><td ><input type="file" name="photo2" id="file2"/></td>
Add this code in your html and check selected images in your "process2.php" those are selected that store in your database.
When you insert this images in your database that time just do "img1,img2,img3" store this in your image colum... This is the simplest way if your requirement is only 3 images then you can follow this.

Checkbox mysql php

<form action="execute_new.php" id="modalform" method="post">
<td width="147"> <strong>
<font color="#033">Sticker No:</font><font color="#FF0000">*</font></td>
<td width="146"><input type="text" name="stickerno" /></td>
<tr>
<td><strong>
<font color="#033">TO : </font></td>
</tr>
<tr>
<td >
<input name="fname" type="text" />
</td>
<td >
<input name="mname" type="text" />
</td>
<td width="143" align="right">
<input name="lname" type="text" />
</td>
</tr>
<tr>
<td>
First Name</font><font color="#FF0000">*</font>
</td>
<td >
Middle Name</font><font color="#FF0000">*</font>
</td>
<td>
Last Name</font><font color="#FF0000">*</font>
</td>
</tr>
</table><br>
<br>
<table>
<tr>
<td><strong>
<font color="#033"> ADDRESS:</font></font><font color="#FF0000">*</font> </td>
<td align="center"><input name="address" type="text" value="" size="70"></td>
</tr>
</table>
<p> </p>
<font color="#033">
<table border="15" bgcolor="#00FF66" bordercolor="#000000" width="650" cellpadding="1" cellspacing="1">
<br>
<br>
<tr>
<td >LICENSE NO:<font color="#FF0000">*</font></td>
<td align="center"><input type="text" name="license"/></td>
<td >BIRTH DATE:</td>
<td align="center"><input name="bdate" id="demo1" type="text"><img src="cal.gif" width="16" height="16" border="0"></td>
<tr>
<td >PLATE NO:<font color="#FF0000">*</font></td>
<td align="center"><input type="text" name="plateno"/></td>
<td >PUV BODY NAME:</td>
<td align="center"><input type="text" name="puvbname" /></td>
</tr>
<tr>
<td >TYPE OF VEHICLE:</td>
<td align="center"><select id="vehicletype" name="vehicletype" style="width:134px">
<option value="Private">Private</option>
<option value="Public">Public</option>
</select>
<td >PUV BODY NO:</td>
<td align="center"><input type="text" name="puvbno" /></td>
</tr>
<tr>
<td >OWNER OF VEHICLE:</td>
<td align="center"><input type="text" name="vehicleowner" /></td>
<td >ADDRESS:</td>
<td align="center"><input type="text" name="taddress" /></td>
</tr>
<tr>
<td >PLACE OF VIOLATION:<font color="#FF0000">*</font></td>
<td align="center"><input type="text" name="violationplace" /></td>
<td>DATE / TIME:<font color="#FF0000">*</font></td>
<td align="center"><input name="datetime" id="demo2" type="text"><img src="cal.gif" width="16" height="16" border="0">
</tr>
</table><br>
<table border="15" bordercolor="#000000" width="150" cellpadding="1" cellspacing="1">
<tr>Confiscated:</tr>
<br>
<tr><td><input type="radio" name="RadioGroup1" value="License ID" id="RadioGroup1_0" checked>License ID</tr><br>
<tr><td><input type="radio" name="RadioGroup1" value="License O.R." id="RadioGroup1_1">License O.R.</tr>
<tr>
<td> <input type="radio" name="RadioGroup1" value="TCP/TOP" id="RadioGroup1_2">
TCP/TOP</tr>
<tr><td><input type="radio" name="RadioGroup1" value="License Plate" id="RadioGroup1_3">
License Plate</tr>
<tr><td><input type="radio" name="RadioGroup1" value="Not Confiscated" id="RadioGroup1_4">
Not Confiscated</tr>
</tr></table><br />
<center><strong>You are hereby cited for committing the traffic violations / checked hereunder</strong><br /></center>
<br>
<br> <table width="100%px" border="7" cellspacing="1" cellpadding="1" bordercolordark="#000000" style="font-size:13px">
<tr>
<td><input type="checkbox" name="cbox[]" value="Unattended/Illegaly Parked Vehicle" />
Unattended / Illegaly Parked Vehicle</td>
<td><input type="checkbox" name="cbox[]" value="Out of Line Operation/Route Violation" />
Out of Line Operation/Route Violation</br></td>
<tr>
<td><input type="checkbox" name="cbox[]" value="Illegal Parking" />
Illegal Parking</td>
<td><input type="checkbox" name="cbox[]" value="Trip Cutting" />
Trip Cutting</br></td>
<tr>
<td><input type="checkbox" name="cbox[]" value="Illegal Topload" />
Illegal Topload</td>
<td>
<input type="checkbox" name="cbox[]" value="Over Charging" />
Over Charging</td></tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Truck Ban/Tricycle Ban" />
Truck Ban/Tricycle Ban</td>
<td><input type="checkbox" name="cbox[]" value="Refusal to Convey Passenger"/>
Refusal to Convey Passenger</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Driving in Slippers/Sleeveless shirt" />
Driving in Slippers/Sleeveless shirt</td>
<td>
<input type="checkbox" name="cbox[]" value="Overspeeding/Drag Racing/Reckless Driving" />Overspeeding/Drag Racing/Reckless Driving</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Driving w/o License/Expired/Invalid License" />
Driving w/o License/Expired/Invalid License</td>
<td><input type="checkbox" name="cbox[]" value="One-way Street Violation" />One-way Street Violation</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="No PUV ID" />
No PUV ID</td>
<td><input type="checkbox" name="cbox[]" value="Illegal Loading/Unloading" />Illegal Loading/Unloading</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Driving Dilapidated">
Driving Dilapidated</td>
<td><input type="checkbox" name="cbox[]" value="Traffic Obstruction"/>Traffic Obstruction</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Junk Vehicle" />
Junk Vehicle</td>
<td><input type="checkbox" name="cbox[]" value="Disregarding Traffic Sign/Light" />Disregarding Traffic Sign/Light</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="No Smoking 20% Discount Sticker" />
No "No Smoking"/20% Discount Sticker</td>
<td><input type="checkbox" name="cbox[]" value="Illegal Blowing of Horn" />Illegal Blowing of Horn</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="No Permit Decalsticker" />
No Permit Decalsticker</td>
<td><input type="checkbox" name="cbox[]" value="Failure to obey Police Order" />Failure to obey Police Order</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Stereo Set Operated at Excessive Sound Volume" />
Stereo Set Operated at Excessive Sound Volume</td>
<td>
<input type="checkbox" name="cbox[]" value="No Helmet/Head Gear" />
No Helmet/Head Gear</td>
<tr>
<td><input type="checkbox" name="cbox[]" value="No Trash Can/Receptacle" />
No Trash Can/Receptacle</td>
<td><input type="checkbox" name="cbox[]" value="Smoke Belching" />
Smoke Belching</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Colorum PUV" />
Colorum PUV</td>
<td><input type="checkbox" name="cbox[]" value="Failure to Switch Headlights" />Failure to Switch Headlights</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="No Plate" />
No Plate</td>
<td><input type="checkbox" name="cbox[]" value="No U-turn" /> No U-turn</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Driving under the Influence of Liquor" />
Driving under the Influence of Liquor</td>
<td><input type="checkbox" name="cbox[]" value="Dirty Plate" />
Dirty Plate</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Counter Flow" />
Counter Flow</td>
<td><input type="checkbox" name="cbox[]" value="Arrogant Driver/Conductor" />Arrogant Driver/Conductor</td>
</tr>
<tr>
<td><input type="checkbox" name="cbox[]" value="Driver's/Conductor's Uniform/I.D." />
Driver's/Conductor's Uniform / I.D.</td>
<td><input type="text" name="oviolation" />
Other Traffic Violations(Specify)</td>
</tr></table>
<br>
</label>
<p align="center">
<p align="center"><strong>Apprehending Office ( Rank & Name )</strong><font color="#FF0000">*</font></p>
<label> </label>
<select name="type" size="1">
<option>Job Order</option>
<option>Permanent</option>
</select>
<input type="text" name="officer" placeholder="Officer Name"/>
</p>
<h5 align="center">PUBLIC ORDER & SAFETY OFFICE</h5>
<h5 align="center"> </h5>
<h5 align="center">
</h5>
</font>
<input type="submit" name="register" value="Add" class="adds"/>
<input type="reset" name="cancel" value="Reset" class="add"/>
<br />
</h5>
</form>
<?php
date_default_timezone_set('Asia/Manila');
$conn=mysql_connect("localhost","root","");
mysql_select_db("dbposo",$conn);
if(isset($_POST['register']))
{
$license=$_POST['license'];
$query = mysql_query("SELECT * FROM tblviolator WHERE license = '$license'");
$fetch_rows = mysql_num_rows($query);
if ( $fetch_rows > 0 )
{
echo "<script>alert('License # already exist')</script>";
header("Refresh: 0;url=new.php");
}
elseif( empty($_POST['stickerno']))
{
echo "<script>alert('Please check if all the * marker field is filled!')</script>";
header("Refresh: 0;url=new.php");
}
else
{
$stickerno=$_POST['stickerno'];
$fname=$_POST['fname'];
$mname=$_POST['mname'];
$lname=$_POST['lname'];
$address=$_POST['address'];
$bdate=$_POST['bdate'];
$plateno=$_POST['plateno'];
$puvbname=$_POST['puvbname'];
$vehicletype=$_POST['vehicletype'];
$puvbno=$_POST['puvbno'];
$vehicleowner=$_POST['vehicleowner'];
$taddress=$_POST['taddress'];
$violationplace=$_POST['violationplace'];
$datetime=$_POST['datetime'];
$confiscated=$_POST['RadioGroup1'];
$violation=$_POST['cbox'];
$oviolation=$_POST['oviolation'];
$type=$_POST['type'];
$officer=$_POST['officer'];
mysql_query("insert into tblviolator(license, stickerno, fname, mname, lname, address, bdate, plateno, puvbname, vehicletype, puvbno, vehicleowner, taddress, violationplace, datetime, confiscated, violation, oviolation, type, officer) values('$license','$stickerno','$fname','$mname','$lname','$address','$bdate','$plateno','$puvbname','$vehicletype','$puvbno','$vehicleowner','$taddress','$violationplace','$datetime','$confiscated','$violation','$oviolation','$type','$officer')",$conn) or die(mysql_error());
echo "<script>alert('Successfully Recorded, <br>
First penalty: 100php!')</script>";
header("Refresh: 0;url=new.php");
}
}
?>
What is my error here?
if you select more than one checkbox then $_POST['cbox'] becomes array .so try this
if(is_array($_POST['cbox']))
$violation=implode(',',$_POST['cbox']);
else
$violation=$_POST['cbox'];
To avoid injection better use http://php.net/manual/de/function.mysql-real-escape-string.php
If you check more than one option for the checkbox the variable $violation will be an array. Try to check multiple options and just safe the first one.
Probably if you want to store it as varchar you shoud concatenate all values.

Getting checkbox values to appear in email with php

Hello I'm having trouble getting my checkbox values to show in my email.
I have looked around and tired many different solutions none seem to work.
I created this application for my web site. Please help me solve this issue.
The form does send an email. information does show up just not for the checkboxes.
This is the html code for the form.
<form id="jobapp" name="jobapp" method="post" action="jobappprocess.php">
<p><span class="h2">Personal Information</span></p>
<table width="742" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td width="121" align="right" valign="middle"><label for="firstname">First Name:</label></td>
<td width="240" align="left" valign="middle"><input name="firstname" type="text" id="firstname" size="30" maxlength="35" /></td>
<td width="106" align="right" valign="middle">Middle Intial:</td>
<td width="241" align="left" valign="middle"><input name="middleintial" type="text" id="middleintial" size="1" maxlength="1" /></td>
</tr>
<tr>
<td align="right" valign="middle">Last Name:</td>
<td align="left" valign="middle"><input name="lastname" type="text" id="lastname" size="30" maxlength="35" /></td>
<td align="right" valign="middle">Social Security
Number:</td>
<td align="left" valign="middle"><input name="ssn" type="text" id="ssn" size="13" maxlength="11" /></td>
</tr>
<tr>
<td align="right" valign="middle"> </td>
<td align="left" valign="middle"> </td>
<td align="right" valign="middle"> </td>
<td align="left" valign="middle"> </td>
</tr>
<tr>
<td align="right" valign="middle">Street Address:</td>
<td align="left" valign="middle"><input name="streetaddress" type="text" id="streetaddress" size="40" maxlength="90" /></td>
<td align="right" valign="middle">City:</td>
<td align="left" valign="middle"><input name="city" type="text" id="city" size="40" maxlength="90" /></td>
</tr>
<tr>
<td align="right" valign="middle"><label for="zipcode2">Zip Code</label></td>
<td align="left" valign="middle"><input name="zipcode" type="text" id="zipcode" size="7" maxlength="5" /></td>
<td align="right" valign="middle">State:</td>
<td align="left" valign="middle"><input name="state" type="text" id="state" size="2" maxlength="2" /></td>
</tr>
<tr>
<td align="right" valign="middle"><p>Previous Address<br />
</p></td>
<td align="left" valign="middle"><input name="previousaddress" type="text" id="previousaddress" size="40" maxlength="90" /></td>
<td colspan="2" align="right" valign="middle"> </td>
</tr>
<tr>
<td align="right" valign="middle">Home Phone:</td>
<td align="left" valign="middle"><input name="homephone" type="text" id="homephone" size="15" maxlength="13" /></td>
<td align="right" valign="middle">Mobile Phone:</td>
<td align="left" valign="middle"><input name="mobilephone" type="text" id="mobilephone" size="15" maxlength="13" /></td>
</tr>
<tr>
<td align="right" valign="middle"><label for="emailaddress">Email Address</label>
: </td>
<td align="left" valign="middle"><input name="emailaddress" type="text" id="emailaddress" size="35" maxlength="40" /></td>
<td colspan="2" align="right" valign="middle"> </td>
</tr>
<tr>
<td align="right" valign="middle">Are you 18 years of age or older?</td>
<td align="left" valign="middle"><label>
<input type="radio" name="areyou18[]" value="Yes" id="areyou18" />
Yes</label>
<br />
<label>
<input type="radio" name="areyou18[]" value="No" id="areyou18" />
No</label></td>
<td colspan="2" align="right" valign="middle"> </td>
</tr>
</table>
<p class="h2">Position Desired</p>
<table width="850" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td width="218" align="right" valign="middle"><label for="positiondesired">What positon are you applying for?</label></td>
<td width="218" align="left" valign="middle"><input name="positiondesired" type="text" id="positiondesired" size="30" maxlength="30" /></td>
<td width="228" align="right"><label for="startdate">What date are you available to start?</label></td>
<td width="150" align="left" valign="middle"><input name="startdate" type="text" id="startdate" size="20" maxlength="10" /></td>
</tr>
<tr>
<td align="right" valign="middle">Type of Employment:</td>
<td align="left" valign="middle"><p>
<label>
<input type="radio" name="typeofemployment[]" value="Full-time" id="TypeofEmployment_0" />
Full-time</label>
<br />
<label>
<input type="radio" name="typeofemployment[]" value="Part-time" id="TypeofEmployment_1" />
Part-time</label>
<br />
</p></td>
<td align="right">Days Available for work:</td>
<td align="left" valign="middle"><p>
<input type="checkbox" name="sunday[]" id="sunday" />
<label for="sunday">sun</label>
</p>
<p>
<input type="checkbox" name="monday[]" id="monday" />
<label for="monday[]">mon</label>
</p>
<p>
<input type="checkbox" name="tuesday[]" id="tuesday" />
<label for="tuesday">tue</label>
</p>
<p>
<input type="checkbox" name="wednesday[]" id="wednesday" />
<label for="wednesday">wed</label>
</p>
<p>
<input type="checkbox" name="thursday[]" id="thursday" />
<label for="thursday">thur</label>
</p>
<p>
<input type="checkbox" name="friday[]" id="friday" />
<label for="friday">fri</label>
</p>
<p>
<input type="checkbox" name="saturday[]" id="saturday" />
<label for="saturday">sat</label>
<br />
</p></td>
</tr>
</table>
<p class="h2">Education</p>
<table width="850" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td align="right" valign="middle"><label for="highschool">High School:</label></td>
<td align="left" valign="middle"><input name="highschool" type="text" id="highschool" size="50" maxlength="50" /></td>
<td align="right" valign="middle"><label for="hsdatesattended">Dates Attended:</label></td>
<td align="left" valign="middle"><input name="hsdatesattended" type="text" id="hsdatesattended" size="30" maxlength="25" /></td>
</tr>
<tr>
<td align="right" valign="middle">Did you Graduate?</td>
<td align="left" valign="middle"><label>
<input type="checkbox" name="hsgraduate[]" value="Yes" id="Graduate_0" />
Yes</label>
<br />
<label>
<input type="checkbox" name="hsgraduate[]" value="No" id="Graduate_1" />
No</label></td>
<td align="right" valign="middle"> </td>
<td align="left" valign="middle"> </td>
</tr>
<tr>
<td align="right" valign="middle"><label for="college2">College or University:</label></td>
<td align="left" valign="middle"><input name="college" type="text" id="college" size="50" maxlength="60" /></td>
<td align="right" valign="middle">Dates Attended:</td>
<td align="left" valign="middle"><input name="collegedates" type="text" id="collegedates" size="30" maxlength="25" /></td>
</tr>
<tr>
<td align="right" valign="middle"><label for="achievements2">Achievements: List your degrees, certificates, and awards, if any.</label></td>
<td align="left" valign="middle"><textarea name="achievements" id="achievements" cols="30" rows="3"></textarea></td>
<td align="right" valign="middle">Did you Graduate?</td>
<td align="left" valign="middle"><input type="checkbox" name="collegegradyes[]" id="yes" />
<label for="yes">yes<br />
<input type="checkbox" name="collegegradno[]" id="no" />
no </label></td>
</tr>
<tr>
<td align="right" valign="middle"><p> </p></td>
<td align="left" valign="middle"><p><br />
</p></td>
<td align="right" valign="middle"> </td>
<td align="left" valign="middle"> </td>
</tr>
<tr>
<td align="right" valign="middle">Have you served as a member of the U.S. Armed Forces?</td>
<td align="left" valign="middle"><label>
<input type="checkbox" name="armedforces[]" value="Yes" id="armedforces" />
Yes</label>
<br />
<label>
<input type="checkbox" name="armedForces[]" value="No" id="armedforces" />
No</label></td>
<td align="right" valign="middle"> </td>
<td align="left" valign="middle"> </td>
</tr>
<tr>
<td align="right" valign="middle">Branch/Services:</td>
<td align="left" valign="middle"><input name="afbranch" type="text" id="afbranch" size="30" maxlength="25" /></td>
<td align="right" valign="middle">Rank/Speciaty</td>
<td align="left" valign="middle"><input name="afrank" type="text" id="afrank" size="30" maxlength="25" /></td>
</tr>
</table>
<p class="h2"> Work Experience</p>
<table width="850" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td width="99" align="right"><label for="presentlastemployer">Present or Last Employer:</label></td>
<td width="287" align="left"><input name="presentlastemployer" type="text" id="presentlastemployer" size="40" maxlength="30" /></td>
<td width="127" align="right"><label for="plphone">Telephone:</label></td>
<td width="150" align="left"><input name="plphone" type="text" id="plphone" size="15" maxlength="13" /> </td>
</tr>
<tr>
<td align="right"><label for="pladdress">Street Address:</label></td>
<td align="left"><input name="pladdress" type="text" id="pladdress" size="40" maxlength="90" /></td>
<td align="right"><label for="plcity">City:</label></td>
<td align="left"><input name="plcity" type="text" id="plcity" size="30" maxlength="25" /></td>
</tr>
<tr>
<td align="right">State:</td>
<td align="left"><input name="plstate" type="text" id="plstate" size="2" maxlength="2" /></td>
<td align="right">Zip Code:</td>
<td align="left"><input name="plzipcode" type="text" id="plzipcode" size="7" maxlength="5" /></td>
</tr>
<tr>
<td align="right">Position Held:</td>
<td align="left"><input name="plposition" type="text" id="plposition" size="30" maxlength="30" /></td>
<td align="right">Dates of Employment:</td>
<td align="left"><input name="pldates" type="text" id="pldates" size="30" maxlength="25" /></td>
</tr>
<tr>
<td align="right">Job Description:</td>
<td align="left"><textarea name="pldescription" id="pldescription" cols="45" rows="5"></textarea></td>
<td align="right">Supervisor:</td>
<td align="left"><input name="plsupervisor" type="text" id="plsupervisor" size="40" maxlength="35" /></td>
</tr>
<tr>
<td align="right">Reason for Leaving:</td>
<td align="left"><p>
<textarea name="plreasonforleaving" id="plreasonforleaving" cols="45" rows="5"></textarea>
<br />
</p></td>
<td align="right">Salary:</td>
<td align="left"><input name="plsalary" type="text" id="plsalary" size="20" maxlength="15" /></td>
</tr>
<tr>
<td align="right">May we contact your present employer?</td>
<td align="left"><label>
<input type="checkbox" name="plmaywecontact[]" value="Yes" id="plmaywecontact" />
Yes</label>
<br />
<label>
<input type="checkbox" name="plmaywecontact[]" value="No" id="plmaywecontact" />
No</label></td>
<td align="right"> </td>
<td align="right"> </td>
</tr>
<tr>
<td colspan="4" align="center" class="h2"> More Work Experience</td>
</tr>
<tr>
<td align="right">Previous Employer:</td>
<td align="left"><input name="previousemployer" type="text" id="previousemployer" size="40" maxlength="30" /></td>
<td align="right">Telephone:</td>
<td align="left"><input name="pephone" type="text" id="pephone" size="15" maxlength="13" /></td>
</tr>
<tr>
<td align="right"><label for="peaddress2">Address:</label></td>
<td align="left"><input name="peaddress" type="text" id="peaddress" size="40" maxlength="50" /></td>
<td align="right">City:</td>
<td align="left"><input name="pecity" type="text" id="pecity" size="30" maxlength="25" /></td>
</tr>
<tr>
<td align="right">State:</td>
<td align="left"><input name="pestate" type="text" id="pestate" size="2" maxlength="2" /></td>
<td align="right">Zip Code:</td>
<td align="left"><input name="pezipcode" type="text" id="pezipcode" size="7" maxlength="5" /></td>
</tr>
<tr>
<td align="right">Position Held:</td>
<td align="left"><input name="peposition" type="text" id="peposition" size="30" maxlength="20" /></td>
<td align="right">Dates of Employment:</td>
<td align="left"><input name="pedates" type="text" id="pedates" size="30" maxlength="25" /></td>
</tr>
<tr>
<td align="right">Job description:</td>
<td align="left"><textarea name="pedescription" id="pedescription" cols="45" rows="5"></textarea></td>
<td align="right">Supervisor</td>
<td align="left"><input name="pesupervisor" type="text" id="pesupervisor" size="35" maxlength="30" /></td>
</tr>
<tr class="agree">
<td align="right">Reason for leaving:</td>
<td align="center" class="agree"><textarea name="peresasonforleaving" id="peresasonforleaving" cols="45" rows="5"></textarea></td>
<td align="right" class="agree">Salary:</td>
<td align="left" class="agree"><input type="text" name="pesalary" id="pesalary" /></td>
</tr>
</table>
<p> </p>
<table width="500" border="0" cellspacing="0" cellpadding="3">
<tr>
<td colspan="2"><span class="agree"></span></td>
</tr>
<tr>
<td width="362" align="center"><span class="h2">Do you accept the terms of this application?</span></td>
<td width="120"><span class="h2">
<label>
<input type="radio" name="acceptterms[]" value="Yes" id="AcceptTermsofapplication_0" />
Yes</label>
<br />
<label>
<input type="radio" name="acceptterms[]" value="No" id="AcceptTermsofapplication_1" />
No</label>
</span></td>
</tr>
<tr>
<td colspan="2" align="center"><input name="submitapp" type="submit" id="Submit Application" onclick="MM_validateForm('firstname','','R','lastname','','R','ssn','','RisNum','streetaddress','','R','city','','R','zipcode','','RisNum','state','','R','homephone','','RisNum','mobilephone','','RisNum','emailaddress','','RisEmail','positiondesired','','R','startdate','','RisNum','highschool','','R','presentlastemployer','','R','pladdress','','R','plstate','','R','plposition','','R','pldates','','R','plsupervisor','','R','plsalary','','NisNum','pephone','','NisNum','pezipcode','','NisNum','pedates','','NisNum','pesalary','','NisNum','pldescription','','R','plreasonforleaving','','R');return document.MM_returnValue" value="Submit Application" /></td>
</tr>
</table>
<p class="h2"> </p>
<p class="h2"> </p>
</form></td>
</tr>
</table>
And this is the php code
<?php
foreach ($_SESSION['Checkbox'] as $val) {
$checkboxresults .= $val.",\n";
}
echo (is_array($_REQUEST['$checkbox']) ? implode("\n", $_REQUEST['$checkbox']) : $_REQUEST['$checkbox']);
/* Subject and Email Variables */
$emailSubject = 'New Job Appilcant!';
$webMaster = '';
$from = 'emailaddressField';
/* Gathering Data Variables */
$firstnameField = $_POST['firstname'];
$lastnameField = $_POST['lastname'];
$middleintialField = $_POST['middleintial'];
$streetaddressField = $_POST['streetaddress'];
$cityField = $_POST['city'];
$stateField = $_POST['state'];
$zipcodeField = $_POST['zipcode'];
$ssnField = $_POST['ssn'];
$previousaddressField = $_POST['previousaddress'];
$homephoneField = $_POST['homephone'];
$mobilephoneField = $_POST['mobilephone'];
$emailaddressField = $_POST['emailaddress'];
$areyou18Field = $_POST['areyou18'];
$positiondesiredField = $_POST['positiondesired'];
$startdateField = $_POST['startdate'];
$typeofemploymentField = $_POST['typeofemployment'];
$sundayField = $_POST ['sunday'];
$mondayField = $_POST ['monday'];
$tuesdayField = $_POST ['tuesday'];
$wednesdayField = $_POST ['wednesday'];
$thursdayField = $_POST ['thursday'];
$fridayField = $_POST ['friday'];
$saturdayField = $_POST ['saturday'];
$highschoolField = $_POST['highschool'];
$hsdatesattendedField = $_POST['hsdatesattended'];
$hsgraduateField = $_POST['hsgraduate'];
$collegeField = $_POST['college'];
$collegedatesField = $_POST['collegedates'];
$collegegradyesField = $_POST['collegegradyes'];
$collegegradnoField = $_POST['collegegradno'];
$achievementsField = $_POST['achievements'];
$armedforcesField = $_POST['armedforces'];
$afbranchField = $_POST['afbranch'];
$afrankField = $_POST['afrank'];
$previouslastemployerField = $_POST['previouslastemployer'];
$plphoneField = $_POST['plphone'];
$pldatesField = $_POST['pldates'];
$pladdressField = $_POST['pladdress'];
$plcityField = $_POST['plcity'];
$plstateField = $_POST['plstate'];
$plzipcodeField = $_POST['plzipcode'];
$plsupervisorField = $_POST['plsupervisor'];
$plpositionField = $_POST['plposition'];
$pldescriptionField = $_POST['pldescription'];
$plsalaryField = $_POST['plsalary'];
$plreasonforleavingField = $_POST['plreasonforleaving'];
$maywecontactField = $_POST['maywecontact'];
$previousemployerField = $_POST['previousemployer'];
$pephoneField = $_POST['pephone'];
$pedatesField = $_POST['pedates'];
$peaddressField = $_POST['peaddress'];
$pecityField = $_POST['pecity'];
$pestateField = $_POST['pestate'];
$pezipcodeField = $_POST['pezipcode'];
$pesupervisorField = $_POST['pesupervisor'];
$pepositionField = $_POST['peposition'];
$pedescriptionField = $_POST['pedescription'];
$pesalaryField = $_POST['pesalary'];
$pereasonforleavingField = $_POST['acceptterms'];
$body = <<<EOD
<br><hr><br>
<p>
Name: $firstnameField $middleintialField $lastnameField <br><br>
Address: $streetaddressField $cityField $stateField $zipcodeField <br><br>
SSN: $ssnField <br><br>
Previous Address: $previousaddressField <br><br>
Home Phone: $homephoneField <br><br>
Mobile Phone: $mobilephoneField <br><br>
Email: $emailaddressField <br><br>
Eight-teen Plus: $areyou18Field <br><br>
Position Desired: $positiondesiredField <br><br>
Date available to start: $startdateField <br><br>
Type of Employment: $typeofemploymentField <br><br>
Days available to work: $sundayField, $mondayField, $tuesdayField, $wednesdayField, $thursdayField, $fridayField, $saturdayField
<br><hr><br>
High School: $highschoolField, $hsdatesattenedField, $hsgraduateField
<br><hr><br>
College: $collegeField, $collegedatesField, $collegegradyesField, $collegegradnoField, $achievements
<br><hr><br>
Armed Forces: $armedforcesField, $afbranchField, $afrankField
<br><hr><br>
Recent Employer <br>
<p>
$presentlastemployerField
$plphoneField
$pldatesField
$pladdressField
$plcityField
$plstateField
$plzipcodeField
$supervisorField
$plpositionField
$pldescriptionField
$plsalaryField
$plreasonforleavingField
$plmaywecontactField</p>
<br><hr><br>
Previous Employer <br>
<p>
$previousemployerField
$pephoneField
$pedatesField
$peaddressField
$pecityField
$pestateField
$pezipcodeField
$pesupervisorField
$pepositionField
$pedescriptionField
$pesalaryField
$pereasonforleavingField</p>
<br><hr><br>
Accept Terms of Employment <br><br>
$accepttermsField
EOD;
$headers = "From: $emailaddressField\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail ($webMaster, $emailSubject, $body, $headers);
?>
As I said the the form does submit. The check box values don't appear.
Thank you for in advance for any help offered.
Try to add 'value' attribute to the each checkbox input. I noticed that you forgot to do it for "Days Available for work" checkboxes.

trouble updating mysql data

I have these codes, used to update mysql database
AIS.php-used to input pnum and then new.php will show the corresponding record for the pnum
<style>
input { font-size: 16px;}
</style>
<?php include('header.php'); ?>
<div id="main_content">
</div>
<?php include('footer.php'); ?>
<table width="900" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="new.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="16" style="background:#9ACD32; color:white; border:white 1px solid; text-align: center"><strong><font size="3">UPDATE IN-PATIENT</strong></td>
</tr>
<tr>
<td width="54"><font size="3">Patient #</td>
<td width="3">:</td>
<td width="168"><input name="pnum" type="text" id="pnum" maxlength="4"></td>
</tr>
<td width="54"><font size="3">Hospital #</td>
<td width="3">:</td>
<td width="168"><input name="hnum" type="text" id="hospnum" maxlength="4"></td>
<td width="41"><font size="3">Room #</td>
<td width="3">:</td>
<td width="168"><input name="rnum" type="text" id="rnum" maxlength="4"></td>
<td width="67"><font size="3">Date</td>
<td width="3">:</td>
<td width="168"><input name="adate" type="text" id="adate" maxlength="15">
<td width="67"><font size="3">Time</td>
<td width="3">:</td>
<td width="168"><input name="adtime" type="text" id="adtime" maxlength="15">
</td>
</tr>
<tr>
<td><font size="3">Last Name</td>
<td>:</td>
<td><input name="lname" type="text" id="lname" maxlength="15"></td>
<td><font size="3">First Name</td>
<td>:</td>
<td><input name="fname" type="text" id="fname" maxlength="15"></td>
<td><font size="3">Middle Name</td>
<td>:</td>
<td><input name="mname" type="text" id="mname" maxlength="15"></td>
</tr>
<tr>
<td><font size="3">Civil Status</td>
<td>:</td>
<td><input name="cs" type="text" id="cs" maxlength="7"></td>
<td><font size="3">Age</td>
<td>:</td>
<td><input name="age" type="text" id="age" maxlength="3"></td>
<td><font size="3">Birthday</td>
<td>:</td>
<td><input name="bday" type="text" id="bday" maxlength="11"></td>
</tr>
<tr>
<td><font size="3">Address</td>
<td>:</td>
<td><input name="ad" type="text" id="ad" maxlength="25"></td>
<td><font size="3">Telephone #</td>
<td>:</td>
<td><input name="telnum" type="text" id="telnum" maxlength="11"></td>
<td width="23"><font size="3">Sex</td>
<td width="3">:</td>
<td width="174"><input name="sex" type="text" id="sex" maxlength="1"></td>
</tr>
<tr>
<td><font size="3">Pls. Check</td>
<td>:</td>
<input type='hidden' name="stats1" value="0">
<td><input name="stats1" type="checkbox" id="SSS" value="SSS">SSS</td>
<td><font size="3"></td>
<td>:</td>
<input type='hidden' name="stats2" value="0">
<td><input name="stats2" type="checkbox" id="nonmed" value="NonMedicare">Non Medicare</td>
<td><font size="3"></td>
<td>:</td>
<input type='hidden' name="stats3" value="0">
<td><input name="stats3" type="checkbox" id="sh" value="stockholder">Stockholder</td>
</tr>
<tr>
<td><font size="3"></td>
<td></td>
<input type='hidden' name="stats4" value="0">
<td><input name="stats4" type="checkbox" id="gsis" value="GSIS">GSIS</td>
<td><font size="3"></td>
<td></td>
<input type='hidden' name="stats5" value="0">
<td><input name="stats5" type="checkbox" id="senior" value="seniorcitizen">Senior-Citizen</td>
<tr>
<td><font size="3"></td>
<td></td>
<input type='hidden' name="stats6" value="0">
<td><input name="stats6" type="checkbox" id="dep" value="dependent">Dependent</td>
<td><font size="3"></td>
<td></td>
<input type='hidden' name="stats7" value="0">
<td><input name="stats7" type="checkbox" id="emp" value="employee">Employee</td>
<td><font size="3"></td>
<td></td>
<input type='hidden' name="stats8" value="0">
<td><input name="stats8" type="text" id="" value="" maxlength="15">Others</td>
</tr>
<tr>
<td><font size="3">Admitting/Attending Nurse</td>
<td>:</td>
<td><input name="nurse" type="text" id="nurse" maxlength="15"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Search"></td>
</form>
</tr>
</table>
</td>
</form>
</tr>
</table>
<table>
<tr><td>
</tr>
</table>
</html>
new.php
<html>
<head>
<style>
input { font-size: 16px;}
</style>
<?php include('header.php'); ?>
<div id="main_content">
</div>
<?php include('footer.php'); ?>
<?php
$con = mysql_connect("localhost","","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("Hospital", $con);
$result = mysql_query("SELECT * FROM t2 WHERE PNUM='{$_POST["pnum"]}'");
?>
<table width="900" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="16" style="background:#9ACD32; color:white; border:white 1px solid; text-align: center"><strong><font size="3">UPDATE IN-PATIENT INFORMATION SHEET</strong></td>
</tr>
<tr>
<?php while ( $row = mysql_fetch_array($result) ) { ?>
<form name="form1" method="post" action="update.php">
<input type='hidden' name="pnum" value="">
<td width="54"><font size="3">Hospital #</td>
<td width="3">:</td>
<td width="168"><input name="hnum" type="text" maxlength="4" value="<?php echo $row["HOSPNUM"]; ?> ">
</td>
<td width="41"><font size="3">Room #</td>
<td width="3">:</td>
<td width="168"><input name="rnum" type="text" maxlength="4" value="<?php echo $row["ROOMNUM"]; ?>">
</td>
<td width="67"><font size="3">Admission Date</td>
<td width="3">:</td>
<td width="168"><input name="adate" type="text" maxlength="15" value="<?php echo $row["ADATE"]; ?>">
</td>
<td width="67"><font size="3">Admission Time</td>
<td width="3">:</td>
<td width="168"><input name="adtime" type="text" maxlength="15" value="<?php echo $row["ADTIME"]; ?>">
</td>
</tr>
<tr>
<td><font size="3">Last Name</td>
<td>:</td>
<td><input name="lname" type="text" maxlength="15" value="<?php echo $row["LASTNAME"]; ?>"></td>
<td><font size="3">First Name</td>
<td>:</td>
<td><input name="fname" type="text" maxlength="15" value="<?php echo $row["FIRSTNAME"]; ?>"></td>
<td><font size="3">Middle Name</td>
<td>:</td>
<td><input name="mname" type="text" maxlength="15" value="<?php echo $row["MIDNAME"]; ?>"></td>
</tr>
<tr>
<td><font size="3">Civil Status</td>
<td>:</td>
<td><input name="cs" type="text" maxlength="7" value="<?php echo $row["CSTAT"]; ?>"></td>
<td><font size="3">Age</td>
<td>:</td>
<td><input name="age" type="text" maxlength="3" value="<?php echo $row["AGE"]; ?>"></td>
<td><font size="3">Birthday</td>
<td>:</td>
<td><input name="bday" type="text" maxlength="7"value="<?php echo $row["BDAY"]; ?>"></td>
</tr>
<tr>
<td><font size="3">Address</td>
<td>:</td>
<td><input name="ad" type="text" maxlength="25" value="<?php echo $row["ADDRESS"]; ?>"></td>
<td><font size="3">Telephone #</td>
<td>:</td>
<td><input name="telnum" type="text" maxlength="11" value="<?php echo $row["TELNUM"]; ?>"></td>
<td width="23"><font size="3">Sex</td>
<td width="3">:</td>
<td width="174"><input name="sex" type="text" maxlength="1" value="<?php echo $row["SEX"]; ?>"></td>
</tr>
<tr>
<td><font size="3">Pls. Check</td>
<td>:</td>
<input type='hidden' name="stats1" value="0">
<td><input name="stats1" type="checkbox" id="SSS" maxlength="3" value="SSS">SSS</td>
<td><font size="3"></td>
<td>:</td>
<input type='hidden' name="stats2" value="0">
<td><input name="stats2" type="checkbox" id="nonmed" maxlength="9" value="Non Med">Non Medicare</td>
<td><font size="3"></td>
<td>:</td>
<input type='hidden' name="stats3" value="0">
<td><input name="stats3" type="checkbox" id="sh" value="stockholder">Stockholder</td>
</tr>
<tr>
<td><font size="3"></td>
<td></td>
<input type='hidden' name="stats4" value="0">
<td><input name="stats4" type="checkbox" id="gsis" value="gsis">GSIS</td>
<td><font size="3"></td>
<td></td>
<input type='hidden' name="stats5" value="0">
<td><input name="stats5" type="checkbox" id="senior" value="senior citizen">Senior-Citizen</td>
<tr>
<td><font size="3"></td>
<td></td>
<input type='hidden' name="stats6" value="0">
<td><input name="stats6" type="checkbox" id="dep" value="Dependent">Dependent</td>
<td><font size="3"></td>
<td></td>
<input type='hidden' name="stats7" value="0">
<td><input name="stats7" type="checkbox" id="emp" value="Employee">Employee</td>
<td><font size="3"></td>
<td></td>
<input type='hidden' name="stats8" value="0">
<td><input name="stats8" type="text" id="" maxlength="15" value="<?php echo $row["STAT8"]; ?>" >Others</td>
</tr>
<tr>
<td><font size="3">Admitting/Attending Nurse</td>
<td>:</td>
<td><input name="nurse" type="text" maxlength="15" value="<?php echo $row["NURSE"]; ?>"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Update"></td>
</form>
</tr>
</table>
</td>
</form>
</tr>
</table>
<?php } ?>
Then finally the update.php
<?php
$con = mysql_connect("localhost","","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("Hospital", $con);
mysql_query("UPDATE t2 SET HOSPNUM ='$_POST[hnum]', ROOMNUM='$_POST[rnum]', ADATE='$_POST[adate]', ADTIME='$_POST[adtime]', LASTNAME='$_POST[lname]', FIRSTNAME='$_POST[fname]', MIDNAME='$_POST[mname]', CSTAT='$_POST[cs]', AGE='$_POST[age]', BDAY='$_POST[bday]', ADDRESS='$_POST[ad]', SEX='$_POST[sex]',
STAT='$_POST[stats1]', STAT2='$_POST[stats2]', STAT3='$_POST[stats3]', STAT4='$_POST[stats4]', STAT5='$_POST[stats5]', STAT6='$_POST[stats6]', STAT7='$_POST[stats7]', STAT8='$_POST[stats8]', NURSE='$_POST[nurse]'
WHERE PNUM ='$_POST[pnum]'");
echo "<script>alert('Data Successfully Updated')</script>";
mysql_close($con)
?>
The problem is, I didn't show the text box corresponding to the pnum(primary key) to prevent it from being updated. Do you know of any technique that would not allow the pnum to be updated even if the text box corresponding to it is shown?
if you don't want to update it, but still need it in your query you can do:
UPDATE `table` SET `col` = `col` WHERE `id` = …

Categories