I have created a form and I am trying to insert the data into a database, but no matter what I try nothing goes. If I enter values as SQL statements from the command line, it works, but not if I try to enter it from the form. I can't get form data variables to get entered, either. If I echo the variables I am trying to insert, the values are echoed.
At the bottom of my code I have a wee sql statement just to see if these few variables (which are "not null") can get inserted. Right before it, I echo the variables just to make sure they are working, and they are.
<?php
//print_r($_POST);
if (isset($_POST['location'])) {
$location = implode ('<br />', $_POST['location']);
} else {
$location = NULL;
}
if (isset($_POST['incidenttype'])) {
$inctype = implode ('<br />', $_POST['incidenttype']);
} else {
$inctype = NULL;
}
if (isset($_POST['Treatment'])) {
$treatment = implode ('<br /> ', $_POST['Treatment']);
} else {
$treatment = null;
}
if (isset($_POST['Transport'])) {
$transport = implode ('<br /> ', $_POST['Transport']);
} else {
$transport = null;
}
if ($_POST['submit']) {
$date = ($_POST['Date']);
$time = ($_POST['Time']);
$AM_PM1 = ($_POST['AM_PM1']);
$firstName = ($_POST['firstName']);
$lastName = ($_POST['lastName']);
$streetAddress = ($_POST['streetAddress']);
$city = ($_POST['city']);
$state = ($_POST['state']);
$zip = ($_POST['zip']);
$gender = ($_POST['gender']);
$age = ($_POST['age']);
$height = ($_POST['height']);
$weight = ($_POST['weight']);
$hair = ($_POST['hair']);
$eyes = ($_POST['eyes']);
$race_ethnic = ($_POST['race_ethnic']);
$otherchar = ($_POST['otherchar']);
$otherpatrons = ($_POST['OtherPatrons']);
$event_desc = ($_POST['EventDescription']);
$police_called = ($_POST['PoliceCalled']);
$time_police_arr = ($_POST['TimePoliceArrived']);
$AM_PM2 = ($_POST['AM_PM2']);
$other_incident = ($_POST['OtherIncident']);
$resume_business = ($_POST['ResumeBusiness']);
$hospital = ($_POST['hospital']);
$othertreatment = ($_POST['OtherTreatment']);
$transportedby = ($_POST['TransportedBy']);
$actions_taken = ($_POST['ActionsTaken']);
$non_staff_involved = ($_POST['NonStaffInvolved']);
$added_comments = ($_POST['AddedComments']);
$staff_present = ($_POST['StaffPresent']);
$report_submit_by = ($_POST['ReportSubmittedBy']);
}
$hostname = "localhost";
$database = "incident_form";
$username = "root";
$password = "nunnayerbeezwax";
$con = mysql_connect($hostname,$username,$password);
if (mysql_select_db($database, $con)) {
echo "Successful connection<br />";
}
echo $date, $time, $report_submit_by;
$sql = "Insert into incident(incid, date, time, author)
values (null,'$date]','$time]','$report_submit_by')";
$result = mysql_query($sql, $con);
This is driving me batty. I have also tried inserting data with the "$_POST[insert_variable_here]" statement, and nothing goes. Usually when I'm this frustrated it means I missed something obvious.
Anyone out there who can help me sort this out?
spivey