我的html表单中所有复选框中的某些文本字段未提交到MySQL数据库。名称和电子邮件等大多数字段都会通过,但我似乎无法弄清楚为什么有些不起作用。这是html代码:
<form action="js/phpsubmit.php" method="post" enctype="multipart/form-data" name="Form" id="Form">
<p>
<table width="978" height="373" border="0">
<tr>
<td width="20%"><label for="name">Full Name</label>
<br />
<input type="text" name="name" id="name" />
</td>
<td width="23%"><label for="email">Email</label>
<br />
<input type="text" name="email" id="email" />
</td>
<td width="57%"><label for="phone">Phone #</label>
<br />
<input type="text" name="phone" id="phone" />
</td>
</tr>
<tr>
<td><label for="address">Address</label>
<br />
<input type="text" name="address" id="address" />
</td>
<td width="23%"><label for="city">City</label>
<br />
<input type="text" name="city" id="city" />
</td>
<td width="57%"><label for="ZipCode">Zip Code</label>
<br />
<input type="text" name="ZipCode" id="ZipCode" />
</td>
</tr>
<tr>
<td><label for="Age">Age</label>
<br />
<input type="text" name="Age" id="Age" />
</td>
<td><label for="Gender">Gender</label>
<br />
<input type="text" name="Gender" id="Gender" />
</td>
<td><label for="DOB">DOB(mm/dd/yyyy)</label>
<br />
<input type="text" name="DOB" id="DOB" />
</td>
</tr>
<tr>
<td colspan="2"><label for="CurrentMedications">Current Medications</label>
<br />
<textarea name="CurrentMedications" id="CurrentMedications" cols="45" rows="5"></textarea></td>
<td><label for="CurrentMedicalConditions">Current Medical Conditions</label>
<br />
<textarea name="CurrentMedicalConditions" id="CurrentMedicalConditions" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td colspan="3"><label for="Comments">Comments</label>
<br />
<textarea name="Comments" id="Comments" cols="45" rows="5"></textarea></td>
</tr>
<tr><td><br /></td></tr>
<tr>
<td colspan="3"><label for="BP">BP</label>
<input name="BP" type="text" id="BP" size="3" />
<label for="P">P</label>
<input name="P" type="text" id="P" size="3" />
<label for="Glu">Glu</label>
<input name="Glu" type="text" id="Glu" size="3" />
<label for="TC">TC</label>
<input name="TC" type="text" id="TC" size="3" />
<label for="W">W</label>
<input name="W" type="text" id="W" size="3" />
<label for="H">H</label>
<input name="H" type="text" id="H" size="3" />
<label for="BMI">BMI</label>
<input name="BMI" type="text" id="BMI" size="3" />
<label for="HBA1C">HBA1C</label>
<input name="HBA1C" type="text" id="HBA1C" size="3" />
<label for="Other">Other</label>
<input name="Other" type="text" id="Other" size="7" /></td>
</tr>
<tr>
<td colspan="3"><table width="934">
<tr>
<th colspan="4"><p> </p>
<p>What Studies are you Interested in?</p></th>
</tr>
<tr>
<td width="260"><label>
<input type="checkbox" name="checkbox[]" value="Acne" />
Acne</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Constipation" />
Constipation</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Hepatitis" />
Hepatitis</label></td>
<td width="203"><label>
<input type="checkbox" name="checkbox[]" value="Rheumatoid Arthritis" />
Rheumatoid Arthritis</label></td>
</tr>
<tr>
<td><label>
<input type="checkbox" name="checkbox[]" value="Alchohol Addiction" />
Alchohol Addiction</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Contraception" />
Contraception</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="High Blood Pressure" />
High Blood Pressure</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Shingles" />
Shingles</label></td>
</tr>
<tr>
<td><label>
<input type="checkbox" name="checkbox[]" value="Allergies" />
Allergies</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Contact Lenses/Solution" />
Contact Lenses/Solution</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="High Cholesterol" />
High Cholesterol</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Sleep Apneal" />
Sleep Apnea</label></td>
</tr>
<tr>
<td><label>
<input type="checkbox" name="checkbox[]" value="Ankle Sprain" />
Ankle Sprain</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Cramp during Menses" />
Cramp during Menses</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="High Triglycerides" />
High Triglycerides</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Sleep Disorders/Insomnia" />
Sleep Disorders/Insomnia</label></td>
</tr>
<tr>
<td><label>
<input type="checkbox" name="checkbox[]" value="Anxiety" />
Anxiety</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Depression" />
Depression</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="HIV or Aids" />
HIV or Aids</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Smoking Cessation" />
Smoking Cessation</label></td>
</tr>
<tr>
<td><label>
<input type="checkbox" name="checkbox[]" value="Asthma" />
Asthma</label></td>
<td width="242"><label>
<input type="checkbox" name="checkbox[]" value="Dermatitis" id="checkbox_22" />
Dermatitis</label>
</td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Hot Flashes" />
Hot Flashes</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Tendonitis" />
Tendonitis</label></td>
</tr>
<tr>
<td><label>
<input type="checkbox" name="checkbox[]" value="Atrial Fibrillation" />
Atrial Fibrillation(AFIB)</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Diabetes type 1" />
Diabetes type 1</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="HPV" />
HPV Vaccine</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Tinnitius" />
Tinnitius (ringing ears)</label></td>
</tr>
<tr>
<td><label>
<input type="checkbox" name="checkbox[]" value="ADD" />
Attention Deficit Disorder(ADD)</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Diabetes type 2" />
Diabetes type 2</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Irritable Bowel Syndrome" />
Irritable Bowel Syndrome</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="UTI" />
Urinary Tract Infections</label></td>
</tr>
<tr>
<td><label>
<input type="checkbox" name="checkbox[]" value="Back Pain" />
Back Pain</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Dibetic Neuropaty" />
Dibetic Neuropathy Pain</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Low Testosterone" />
Low Testosterone</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Vaccine Trials" />
Vaccine Trials in General</label></td>
</tr>
<tr>
<td><label>
<input type="checkbox" name="checkbox[]" value="Bipolar" />
Bipolar Disorder</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Diarrhea" />
Diarrhea</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Migraines/headaches" />
Migraines/Headaches</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Yeast infections" />
Yeast Infections</label></td>
</tr>
<tr>
<td><label>
<input type="checkbox" name="checkbox[]" value="Breast Pain" />
Breast Pain</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Dry Eye" />
Dry Eye</label></td>
<td width="209"><label>
<input type="checkbox" name="checkbox[]" value="Obesity" />
Obesity</label></td>
<td> </td>
</tr>
<tr>
<td><label>
<input type="checkbox" name="checkbox[]" value="Cancer" />
Cancer</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Endometiosis" />
Endometriosis</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Osteoarthritis" />
Osteoarthritis</label></td>
<td> </td>
</tr>
<tr>
<td><label>
<input type="checkbox" name="checkbox[]" value="Childhood Vacs" />
Childhood Vaccinations</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Erectile Dysfunction" />
Erectile Dysfunction</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Osteoporosis" />
Osteoporosis</label></td>
<td> </td>
</tr>
<tr>
<td><label>
<input type="checkbox" name="checkbox[]" value="Chronic Bronchitis" />
Chronic Bronchitis</label></td>
<td width="242"><label>
<input type="checkbox" name="checkbox[]" value="Fibromyalgia" />
Fibromyalgia</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Overactive Bladder" />
Overactive Bladder</label></td>
<td> </td>
</tr>
<tr>
<td><label>
<input type="checkbox" name="checkbox[]" value="Chronic Kidney Disease" />
Chronic Kidney Disease</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Flu" />
Flu/Seasonal Allergies</label></td>
<td><label>
<input type="checkbox" name="checkbox[]" value="Pain Management" />
Pain Management</label></td>
<td> </td>
</tr>
<tr>
<td class="auto-style1"><label>
<input type="checkbox" name="checkbox[]" value="Chronic Obstructive Pulmonary Disease" />
Chronic Obstructive Pulmonary Disease</label></td>
<td class="auto-style1"><label>
<input type="checkbox" name="checkbox[]" value="Healthy Patient Trials" />
Healthy Patient Trials</label></td>
<td class="auto-style1"><label>
<input type="checkbox" name="checkbox[]" value="Psoriasis" />
Psoriasis</label></td>
<td class="auto-style1"></td>
</tr>
<tr>
<td class="auto-style1"><label>
<input type="checkbox" name="checkbox[]" value="Cold Sores" />
Cold Sores</label></td>
<td class="auto-style1"><label>
<input type="checkbox" name="checkbox[]" value="Heartburn" />
Heartburn</label></td>
<td class="auto-style1"><label>
<input type="checkbox" name="checkbox[]" value="Restless Leg Syndrome" />
Restless Leg Syndrome</label></td>
<td class="auto-style1"></td>
</tr>
<tr><td><br /></td></tr>
<tr><td><br /></td></tr>
<tr>
<td colspan="4" align="center"><input name="Submit" type="submit" style="padding: 4px 10px 4px 10px; background-color: #FFFFFF; border: 2px solid #FF9900; font-weight: bold; color: #333333;" /></td>
</tr>
</table></td>
</tr>
</table>
</form>
这是php代码:
<?php
$con=mysqli_connect("localhost","","","");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sudies=$_POST['checkbox'];
if(count($studies) > 0)
{
$studies_string = implode(",", $studies);
}
// escape variables for security
$name = mysqli_real_escape_string($con, $_POST['name']);
$phone = mysqli_real_escape_string($con, $_POST['phone']);
$age = mysqli_real_escape_string($con, $_POST['Age']);
$gender = mysqli_real_escape_string($con, $_POST['Gender']);
$dob = mysqli_real_escape_string($con, $_POST['DOB']);
$comments = mysqli_real_escape_string($con, $_POST['Comments']);
$study = mysqli_real_escape_string($con, $studies_string);
$medications = mysqli_real_escape_string($con, $_POST['CurrentMedications']);
$conditions = mysqli_real_escape_string($con, $_POST['CurrentMedicalConditions']);
$bp = mysqli_real_escape_string($con, $_POST['BP']);
$p = mysqli_real_escape_string($con, $_POST['P']);
$glu = mysqli_real_escape_string($con, $_POST['Glu']);
$tc = mysqli_real_escape_string($con, $_POST['TC']);
$w = mysqli_real_escape_string($con, $_POST['W']);
$h = mysqli_real_escape_string($con, $_POST['H']);
$bmi = mysqli_real_escape_string($con, $_POST['BMI']);
$hba1c = mysqli_real_escape_string($con, $_POST['HBA1C']);
$ohter = mysqli_real_escape_string($con, $_POST['Other']);
$email = mysqli_real_escape_string($con, $_POST['email']);
$address = mysqli_real_escape_string($con, $_POST['address']);
$city = mysqli_real_escape_string($con, $_POST['city']);
$zipcode = mysqli_real_escape_string($con, $_POST['ZipCode']);
$sql="INSERT INTO Patients (Name, Phone, Age, Gender, DOB, Comments, InterestedStudies, Email, Address, City, Zipcode, CurrentMedication, CurrentmedicalConditions, BP, P, Glu, TC, W, H, BMI, HBA1C, Other)
VALUES ('$name', '$phone', '$age', '$gender', '$dob', '$comments', '$study', '$email', '$address', '$city', '$zipcode', '$medications', '$conditions', '$bp', '$p', '$glue', '$tc', '$w', '$h', '$bmi', '$hba1c', '$other')";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
header('Location: thank-you.html');
?>
提前致谢。