Jump to content

To Read or Not to Read....Database won't save this form data


kenwvs

Recommended Posts

I have built a basic form, and want it to be saved to my database.  I have a good database connection as the technician names are displayed in the drop down box.  The problem is when you press submit, it isn't saved to the database.  I have the print command at the bottom and all the fields show the data except for the technician drop down field.  It remains empty and am not sure what is wrong that this data isn't being accepted for inclusion into the database.  Any ideas what is causing these problems.  Also, I am a newbie, and if I understand correctly, if in the DB I have a field set as NULL, then I could leave this field blank in the form or are they even related?

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

?></select>
&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>
</select>
</div> <BR>
<div> Unit Serial #:<input type="text" size="10" maxlength="10" name="Serial">
&nbsp;&nbsp;
Unit Hours:<input type="text" size="6" maxlength="6" name="Hours">
&nbsp;&nbsp;
Unit Starts:<input type="text" size="6" maxlength="6" name="Starts">
&nbsp;&nbsp;
&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>
</select>
&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>
</select>
</div> <BR>
<div>Description of Issue:<BR><textarea rows="4" name="Issue" cols="116"></textarea>
</div><BR>
<div>Possible Resolution<BR><textarea rows="4" name="Resolve" cols="116"> </textarea>
</div><BR>
<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><BR>

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

<p align="center"><input type="submit" name="Submit" value="Submit Work Order">  <BR>
<p align="center"><input type="reset" name="Submit" value="Clear Form">
</form>
<?php
print_r($_POST);
?>
<?php
} 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!";
}
?>
</body>
</html>[/code]
Link to comment
Share on other sites

I know they look wierd, but I am sure I am using the right keys.  I am using the key to the right of the enter and same key that the " is on.

That is the same key tht I have around the table name, isn't that correct?  When I created the darn table name I was going through a tutorial and it never said that I couldnt use two words....having said that I can see the grief it causes and am changing it to a single name, although I don't think that is the problem, I will try anything about now.......
Link to comment
Share on other sites

I am gettnig an error in my sql syntax and need to know what the right syntax is to use where I have put a [color=red]red question mark[/color].  Please be specific as to where the key is located, not just what it is called...they all look almost the same.  I am thinking it is suppose to be the non capital of the button beside the enter key

mysql_query("INSERT INTO [color=red]?[/color]order[color=red]?[/color](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());
Link to comment
Share on other sites

I have surrounded the table with the `  ` keys and now when I run the form the database is accessed, and the id autoincrements by one, but no other fields are filled in the database.  When I look at the results that print, the technician field (which is the only field where data is obtained from another table) is blank.  It is a dropdown box, and the names are in the box, but they aren't making it to the print or submit command.
Link to comment
Share on other sites

Well, that's already progress -- the INSERT no longer fails.  I can't say why the other fields are blank... I assume that if you echo the interpolated query, you'll see empty values too.  Again, I'm leaning towards a quoting problem.
Link to comment
Share on other sites

Yeah, I would say the problem now lies with where you have code like this
[code]
$Technician = $_POST[‘Tech’];
[/code]

I don't know what those encapsulating quote marks are but they should be either
[code]
$Technician = $_POST['Tech'];
[/code]
or
[code]
$Technician = $_POST["Tech"];
[/code]

BTW try not to use reserved words like "order" for your table names or column names, then you don't need to worry about backticks.
Link to comment
Share on other sites

I have changed the table name and the column name away from reserved words.  I didn't actually realize that order was a reserved word (if you look up newbie in the dictionary, my picture is there).  I don't know why my encapsulating quote marks get so weird looking , but I will change them to double quotes, then see what happens.  I am also thinking that doing a foreach statement may help find any problems, but I don't understand this concept and am having troubles following how to set it up.  I will keep working on this and see where it goes.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.