Jump to content


Photo

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


  • Please log in to reply
16 replies to this topic

#1 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 03 August 2006 - 05:11 AM

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
<?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>


#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 03 August 2006 - 02:15 PM

You need to backtick the table name, not quote it... not that you should EVER have a table name with a space in it.  Also, those quotes look strange for your associative arrays.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 03 August 2006 - 02:21 PM

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.......

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 03 August 2006 - 02:28 PM

You don't want to pass your table name as a string literal, but rather enclosed in backticks to escape it.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 03 August 2006 - 02:44 PM

Where is the backtick key found.  I am not sure where you see that I have it in quotation marks, unless you are referring to the whole statement starting with INSERT INTO

#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 03 August 2006 - 03:45 PM

That's precisely where I see it... it's the key with the tilde on it.  See what mysql_error() says.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#7 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 03 August 2006 - 03:49 PM

What is a tilde. ..............

#8 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 03 August 2006 - 03:50 PM

~
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#9 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 03 August 2006 - 03:52 PM

and that is what should be around the table name, cause that isn't what I have

#10 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 03 August 2006 - 04:07 PM

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 red question mark.  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 ?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());

#11 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 03 August 2006 - 04:26 PM

Well, if you don't have any spaces, and you don't use any reserved keywords, you don't need to quote the table name at all (the ideal case).  I don't know where the tilde is on your keyboard.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#12 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 03 August 2006 - 04:44 PM

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.

#13 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 03 August 2006 - 05:18 PM

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.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#14 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 03 August 2006 - 09:34 PM

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

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

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.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#15 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 04 August 2006 - 12:35 AM

Agreed!
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#16 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 04 August 2006 - 12:42 AM

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.

#17 kenwvs

kenwvs
  • Members
  • PipPipPip
  • Advanced Member
  • 194 posts

Posted 04 August 2006 - 07:40 AM

This is now resolved.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users