kenwvs Posted August 3, 2006 Share Posted August 3, 2006 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]<?phpinclude_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"> <?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> 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"> Unit Hours:<input type="text" size="6" maxlength="6" name="Hours"> Unit Starts:<input type="text" size="6" maxlength="6" name="Starts"> 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> 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><?phpprint_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] Quote Link to comment Share on other sites More sharing options...
fenway Posted August 3, 2006 Share Posted August 3, 2006 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. Quote Link to comment Share on other sites More sharing options...
kenwvs Posted August 3, 2006 Author Share Posted August 3, 2006 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....... Quote Link to comment Share on other sites More sharing options...
fenway Posted August 3, 2006 Share Posted August 3, 2006 You don't want to pass your table name as a string literal, but rather enclosed in backticks to escape it. Quote Link to comment Share on other sites More sharing options...
kenwvs Posted August 3, 2006 Author Share Posted August 3, 2006 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 Quote Link to comment Share on other sites More sharing options...
fenway Posted August 3, 2006 Share Posted August 3, 2006 That's precisely where I see it... it's the key with the tilde on it. See what mysql_error() says. Quote Link to comment Share on other sites More sharing options...
kenwvs Posted August 3, 2006 Author Share Posted August 3, 2006 What is a tilde. .............. Quote Link to comment Share on other sites More sharing options...
fenway Posted August 3, 2006 Share Posted August 3, 2006 ~ Quote Link to comment Share on other sites More sharing options...
kenwvs Posted August 3, 2006 Author Share Posted August 3, 2006 and that is what should be around the table name, cause that isn't what I have Quote Link to comment Share on other sites More sharing options...
kenwvs Posted August 3, 2006 Author Share Posted August 3, 2006 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 keymysql_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()); Quote Link to comment Share on other sites More sharing options...
fenway Posted August 3, 2006 Share Posted August 3, 2006 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. Quote Link to comment Share on other sites More sharing options...
kenwvs Posted August 3, 2006 Author Share Posted August 3, 2006 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. Quote Link to comment Share on other sites More sharing options...
fenway Posted August 3, 2006 Share Posted August 3, 2006 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. Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 3, 2006 Share Posted August 3, 2006 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. Quote Link to comment Share on other sites More sharing options...
fenway Posted August 4, 2006 Share Posted August 4, 2006 Agreed! Quote Link to comment Share on other sites More sharing options...
kenwvs Posted August 4, 2006 Author Share Posted August 4, 2006 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. Quote Link to comment Share on other sites More sharing options...
kenwvs Posted August 4, 2006 Author Share Posted August 4, 2006 This is now resolved. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.