View Full Version : Data won't send to DB

08-03-2006, 07:16 AM
This is a pretty basic form but for some reason the results won't send to the database. I know the DB connection is good because the technician drop down box gets the data from the DB. That is the one field that won't send data out either. I have added the print() to check it and all fields are being sent except the technician field.(only one obtaining data from DB) Any ideas why the technician field won't work and why it won't send data to the DB

include_once "myconnect.php";
/* WorkOrder.php */
if (!isset($_POST['submit'])){
<link href="ge.css" rel="stylesheet" type="text/css">
<title>GE Work Order</title>
<form action="" method="post">
<div>Work Order #:<input type="text" size="12" maxlength="12" name="order">
$result = mysql_query("SELECT * FROM employees") or die(mysql_error());
echo "Technician Name:<select name='tech'>";
echo"<option value=\"{$row[Employee_ID]}\">{$row[First_Name]} {$row[Last_Name]}</option>";

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Site:<select name="Site">
<option value="No Selection Made">Select Site</option>
<option value="Burdett">Burdett</option>
<option value="Coaldale">Coaldale</option>
<option value="Fort McLeod">Fort McLeod</option>
<option value="Taber">Taber</option>
</div> <BR>
<div> Unit Serial #:<input type="text" size="10" maxlength="10" name="Serial">
Unit Hours:<input type="text" size="6" maxlength="6" name="Hours">
Unit Starts:<input type="text" size="6" maxlength="6" name="Starts">
&nbsp;&nbsp; Severity:<select name="Severe">
<option value="No Selection Made">Please Select Level</option>
<option value="Low Level">Low Level</option>
<option value="A.S.A.P.">A.S.A.P.</option>
<option value="Immediate Attention">Immediate Attention</option>
<option value="Severe">Severe</option>
&nbsp;&nbsp; Safety:<select name="Safe">
<option value="No Selection Made">Please Select Level</option>
<option value="Low Risk of Injury">Low Risk of Injury</option>
<option value="Medium Risk of Injury">Medium Risk of Injury</option>
<option value="High Risk of Injury">High Risk of Injury</option>
<option value="Injury has Occurred">Injury has Occurred</option>
</div> <BR>
<div>Description of Issue:<BR><textarea rows="4" name="Issue" cols="116"></textarea>
<div>Possible Resolution<BR><textarea rows="4" name="Resolve" cols="116"> </textarea>
<div>List of Parts Required (known at this time):</div>
<div><input type="text" size="155" maxlength="155" name="PartsA"><BR>
<input type="text" size="155" maxlength="155" name="PartsB"><BR>
<input type="text" size="155" maxlength="155" name="PartsC"><BR>
<input type="text" size="155" maxlength="155" name="PartsD"><BR>
<input type="text" size="155" maxlength="155" name="PartsE"><BR>
<input type="text" size="155" maxlength="155" name="PartsF"><BR>
<input type="text" size="155" maxlength="155" name="PartsG"><BR>

<div>Request for Assistance:<BR><textarea rows="4" name="Assist" cols="116"></textarea>

<p align="center"><input type="submit" name="Submit" value="Submit Work Order"> <BR>
<p align="center"><input type="reset" name="Submit" value="Clear Form">
} else {
$Technician = $_POST[‘Tech’];
$Site = $_POST[‘Site’];
$Serial = $_POST[‘Serial’];
$Hours = $_POST[‘Hours’];
$Starts = $_POST[‘Starts’];
$Issue = $_POST[‘Issue’];
$Resolution = $_POST[‘Resolve’];
$Assistance = $_POST[‘Assist’];
$PartsA = $_POST[‘PartsA’];
$PartsB = $_POST[‘PartsB’];
$PartsC = $_POST[‘PartsC’];
$PartsD = $_POST[‘PartsD’];
$PartsE = $_POST[‘PartsE’];
$PartsF = $_POST[‘PartsF’];
$PartsG = $_POST[‘PartsG’];
$Safety = $_POST[‘Safe’];
$Severity = $_POST[‘Severe’];
mysql_query("INSERT INTO 'work order'(Technician, Site, Serial, Hours, Starts, Issue, Severity, Resolution, Assistance,
PartsA, PartsB, PartsC, PartsD, PartsE, PartsF, PartsG, Safety,) VALUES ('$Technician', '$Site', '$Serial',
'$Hours', '$Starts', '$Issue', '$Severity', '$Resolution', '$Assistance','$PartsA', '$PartsB', '$PartsC', '$PartsD',
'$PartsE', '$PartsF', '$PartsG', '$Safety')");
echo "Your Work Order Has Been Successfully Submitted!";

08-03-2006, 09:13 AM
when queries fail, it's immensely useful to know exactly what it is that is sent to the database.
So, whenever you have mysql_query(), expand it to be something like:

$query='INSERT INTO '; //etc.
mysql_query($query) or die (mysql_error().$query);

then, if you're still stuck, you can post the error message and the actual query to mysql forums, so people wanting to help you don't have to wade through lines and lines of probably irrelevant php and html.

Does the technician happen to have an ' in his name? (good old mr O'Reilly perhaps?)
All data going into mysql should first be put through the escaping function mysql_real_escape_string()

08-03-2006, 09:17 AM
I am getting the successful sent page when I try it on my local server/db, but when i check the db the results are not there. I am not getting an error showing up at all.

I can't figure out what is happening that it won't actually make it to the database. On line 6 I had a capital letter missing which has been fixed, and that is why i now get the success page.


08-03-2006, 05:15 PM
You're getting the success message becuase you are printing it regardless ;)
You have single quotes around your table name, which should be removed + you have a comma after your last field name in your column listing. As suggested by GJay add mysql_error() as well(which probably would've pointed these out for you).

$result = mysql_query("INSERT INTO 'work order'(Technician, Site, Serial, Hours, Starts, Issue, Severity, Resolution, Assistance,
PartsA, PartsB, PartsC, PartsD, PartsE, PartsF, PartsG, Safety,) VALUES ('$Technician', '$Site', '$Serial',
'$Hours', '$Starts', '$Issue', '$Severity', '$Resolution', '$Assistance','$PartsA', '$PartsB', '$PartsC', '$PartsD',
'$PartsE', '$PartsF', '$PartsG', '$Safety')") or die(mysql_error());
echo "Your Work Order Has Been Successfully Submitted!";
echo 'Something went wrong';

Good luck;