Code Help Please
Posted: Wed Dec 08, 2010 4:45 pm
I'm working on creating a form, and keep getting an error querying database message. I assume the connection is fine and there is something wrong with the query itself, but I'm just not spotting the issue (or issues)..
Here is the html code that goes with the php code:
[text]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Troop 97 Permission Form</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<style>
.legal {
font-size:11px;
font-style:italic;
}
</style>
</head>
<body>
<h2>Troop 97 Permission Slip</h2>
<form method="post" action="permission.php">
<label for="activity">Activity:</label>
<input type="text" id="activity" name="activity" /><br />
<label for="date">Date(s):</label>
<input type="text" id="date" name="date" /><br />
<label for="location">Location</label>
<input type="text" id="location" name="location" /><br />
<label for="scoutname">Scout Name(s)</label>
<input type="text" id="scoutname" name="scoutname" /><br />
<label for="attending">List any other people attending:</label>
<input type="text" id="attending" name="attending" /><br />
<label for="parent">Parent/Guardian Name</label>
<input type="text" id="parent" name="parent" /><br />
<label for="primaryphone">Primary Phone</label>
<input type="text" id="primaryphone" name="primaryphone" size="32" /><br />
<label for="alternatephone">Alternate Phone</label>
<input type="text" id="alternatephone" name="alternatephone" size="32" /><br />
<label for="alternatecontact">Alternate Contact</label>
<input type="text" id="alternatecontact" name="alternatecontact" size="32" /><br />
<label for="alternatecontactphone">Alternate Contact Phone</label>
<input type="text" id="alternatecontact" name="alternatecontact" size="32" /><br />
<label for="physical">Are there any changes to your child's (or your own) medical condition since his last BSA Medical Form was submitted?</label>
Yes <input id="physical" name="physical" type="radio" value="yes" />
No <input id="physical" name="physical" type="radio" value="no" /><br />
<label for="other">Describe changes</label>
<textarea id="other" name="other"></textarea><br />
<label for="medicine">Are there any changes to your child's (or your own) medications (including over the counter drugs) since his last BSA Medical Form was submitted?</label>
Yes <input id="medicine" name="medicine" type="radio" value="yes" />
No <input id="medicine" name="medicine" type="radio" value="no" /><br />
<label for="other2">Describe changes</label>
<textarea id="other2" name="other2"></textarea><br />
<p>It is each scout/family's responsibility to arange for transportation to any activity. While the troop will endeavor to accomodate scouts who do not have transportation, we cannot guarantee that room will be available.</p>
<label for="transport">Is your scout being transported to and/or from the activity by a parent or guardian?</label>
Yes <input id="transport" name="transport" type="radio" value="yes" />
No <input id="transport" name="transport" type="radio" value="no" /><br />
<label for="transport2">If no, have you arranged for transportation with another troop member?</label>
Yes <input id="transport2" name="transport2" type="radio" value="yes" />
No <input id="transport2" name="transport2" type="radio" value="no" /><br />
<label for="other3">If yes, provide name of family who will be transporting</label>
<input type="text" id="other3" name="other3" /><br />
<p class="legal"><input type="checkbox" name="legal[]" value="signed">As the parent or legal guardian of the above named scout(s) I hereby give my permission for my son(s) to participate in the above-mentioned activity. I give permission to the leaders of the above unit, to render first aid, should the need arise. In the event of an emergency, I also give permission to the adult leader in charge, to secure proper medical treatment, and for the medical provider(s) so selected to hospitalize, secure proper anesthesia, order injection, or secure other medical treatment, as needed. I further agree to hold the above named unit and its leaders blameless for any accidents that might occur during this outing except for clear acts of negligence or non-adherence to BSA policies and guidelines. </p>
<input type="submit" value="Submit Form" name="submit" />
</form>
</body>
</html>
[/text]
Code: Select all
<?php
$activity = $_POST['activity'];
$date = $_POST['date'];
$location = $_POST['location'];
$scout_name = $_POST['scoutname'];
$attending = $_POST['attending'];
$parent = $_POST['parent'];
$primary_phone = $_POST['primaryphone'];
$alternate_phone = $_POST['alternatephone'];
$alternate_contact = $_POST['alternatecontact'];
$alternate_contact_phone = $_POST['alternatecontactphone'];
$physical = $_POST['physical'];
$other = $_POST['other'];
$medicine = $_POST['medicine'];
$other_2 = $_POST['other2'];
$transport = $_POST['transport'];
$transport_2 = $_POST['transport2'];
$other_3 = $_POST['other3'];
$legal = $_POST['legal'];
$dbc = mysql_connect(localhost, 'troop97_test', 'test1234');
mysql_select_db('troop97_permissions', $dbc)
or die('Error connecting to MYSQL server.');
$query = "INSERT INTO permission_form (activity, date, location, scout_name, " .
"attending, parent, primary_phone, alternate_phone, alternate_contact, alternate_contact_phone, " .
"physical, other, medicine, other_2, transport, transport_2, other_3, legal) " .
"VALUES ('$activity', '$date', '$location', '$scout_name', " .
"'$attending', '$parent', '$primary_phone', '$alternate_phone', '$alternate_contact', '$alternate_contact_phone', " .
"'$physical', '$other', '$medicine', '$other_2', '$transport', '$transport_2', '$other_3', 'legal') " ;
$result = mysql_query($query, $dbc)
or die('Error querying database.');
mysql_close($dbc);
echo 'Thanks for submitting the permission form.<br>';
?>
[text]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Troop 97 Permission Form</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<style>
.legal {
font-size:11px;
font-style:italic;
}
</style>
</head>
<body>
<h2>Troop 97 Permission Slip</h2>
<form method="post" action="permission.php">
<label for="activity">Activity:</label>
<input type="text" id="activity" name="activity" /><br />
<label for="date">Date(s):</label>
<input type="text" id="date" name="date" /><br />
<label for="location">Location</label>
<input type="text" id="location" name="location" /><br />
<label for="scoutname">Scout Name(s)</label>
<input type="text" id="scoutname" name="scoutname" /><br />
<label for="attending">List any other people attending:</label>
<input type="text" id="attending" name="attending" /><br />
<label for="parent">Parent/Guardian Name</label>
<input type="text" id="parent" name="parent" /><br />
<label for="primaryphone">Primary Phone</label>
<input type="text" id="primaryphone" name="primaryphone" size="32" /><br />
<label for="alternatephone">Alternate Phone</label>
<input type="text" id="alternatephone" name="alternatephone" size="32" /><br />
<label for="alternatecontact">Alternate Contact</label>
<input type="text" id="alternatecontact" name="alternatecontact" size="32" /><br />
<label for="alternatecontactphone">Alternate Contact Phone</label>
<input type="text" id="alternatecontact" name="alternatecontact" size="32" /><br />
<label for="physical">Are there any changes to your child's (or your own) medical condition since his last BSA Medical Form was submitted?</label>
Yes <input id="physical" name="physical" type="radio" value="yes" />
No <input id="physical" name="physical" type="radio" value="no" /><br />
<label for="other">Describe changes</label>
<textarea id="other" name="other"></textarea><br />
<label for="medicine">Are there any changes to your child's (or your own) medications (including over the counter drugs) since his last BSA Medical Form was submitted?</label>
Yes <input id="medicine" name="medicine" type="radio" value="yes" />
No <input id="medicine" name="medicine" type="radio" value="no" /><br />
<label for="other2">Describe changes</label>
<textarea id="other2" name="other2"></textarea><br />
<p>It is each scout/family's responsibility to arange for transportation to any activity. While the troop will endeavor to accomodate scouts who do not have transportation, we cannot guarantee that room will be available.</p>
<label for="transport">Is your scout being transported to and/or from the activity by a parent or guardian?</label>
Yes <input id="transport" name="transport" type="radio" value="yes" />
No <input id="transport" name="transport" type="radio" value="no" /><br />
<label for="transport2">If no, have you arranged for transportation with another troop member?</label>
Yes <input id="transport2" name="transport2" type="radio" value="yes" />
No <input id="transport2" name="transport2" type="radio" value="no" /><br />
<label for="other3">If yes, provide name of family who will be transporting</label>
<input type="text" id="other3" name="other3" /><br />
<p class="legal"><input type="checkbox" name="legal[]" value="signed">As the parent or legal guardian of the above named scout(s) I hereby give my permission for my son(s) to participate in the above-mentioned activity. I give permission to the leaders of the above unit, to render first aid, should the need arise. In the event of an emergency, I also give permission to the adult leader in charge, to secure proper medical treatment, and for the medical provider(s) so selected to hospitalize, secure proper anesthesia, order injection, or secure other medical treatment, as needed. I further agree to hold the above named unit and its leaders blameless for any accidents that might occur during this outing except for clear acts of negligence or non-adherence to BSA policies and guidelines. </p>
<input type="submit" value="Submit Form" name="submit" />
</form>
</body>
</html>
[/text]