jackie11 Posted January 17, 2007 Share Posted January 17, 2007 Hi all, I need some help again, I am working on a form to allow people to upload info onto my db, but its not working and I don't know why, I am new to all this so it could be something simple, just not sure if I'm setting it up right I'm using the following scripts, but when I test the form I get a message saying 'Query was empty' Can anyone please help, my head is about to explode!!!!!!!ThanksJackieForm.php[code]<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head> <title>form.php</title> <link rel="stylesheet" href="etc/TJConsultants.css"></head><body><br><div id="wrapper"><div id="header"><div style="text-align: center;"><br></div><br></div><div id="centercolumn"><div style="text-align: center;"><br></div><div style="text-align: center;"><hr style="width: 100%; height: 2px;"><font style="color: rgb(21, 27, 84);" size="+3">NewEmployee Entry Form<br></font><hr style="width: 100%; height: 2px;"><font style="color: rgb(21, 27, 84);" size="+3"><br></font><form method="post" action="script_1.php"><input name="employee_id" value="null" type="hidden"> <table style="text-align: left; margin-left: auto; margin-right: auto; width: 490px; height: 495px;" border="1" cellpadding="2" cellspacing="2"> <tbody> <tr> <td style="text-align: left; vertical-align: middle; font-family: Tahoma; color: rgb(0, 0, 102);">EmployeeID:</td> <td><input name="Employee_ID" size="40" align="right" type="text"></td> </tr> <tr> <td style="font-family: Tahoma; color: rgb(0, 0, 102);">Surname:</td> <td><input name="Surname" size="40" type="text"></td> </tr> <tr> <td style="font-family: Tahoma; color: rgb(0, 0, 102);">Forename:</td> <td><input name="Forename" size="40" type="text"></td> </tr> <tr> <td style="font-family: Tahoma; color: rgb(0, 0, 102);">JobTitle:</td> <td><input name="Job_title" size="40" type="text"></td> </tr> <tr> <td style="font-family: Tahoma; color: rgb(0, 0, 102);">DOB:</td> <td><input name="DOB" size="40" type="text"></td> </tr> <tr> <td style="font-family: Tahoma; color: rgb(0, 0, 102);">Telephone:</td> <td><input name="Telephone" size="40" type="text"></td> </tr> <tr> <td style="font-family: Tahoma; color: rgb(0, 0, 102);">Email:</td> <td><input name="Email" size="40" type="text"></td> </tr> <tr> <td style="font-family: Tahoma; color: rgb(0, 0, 102);">OfficeLocation:</td> <td><input name="Office_location" size="40" type="text"></td> </tr> <tr> <td style="text-align: left; font-family: Tahoma; color: rgb(0, 0, 102);">Expertise:</td> <td><textarea rows="2" name="Expertise" cols="35"></textarea></td> </tr> <tr> <td style="font-family: Tahoma; color: rgb(0, 0, 102);">Hobbies:</td> <td><textarea rows="2" name="Hobbies" cols="35"></textarea></td> </tr> <tr> <td style="font-family: Tahoma; color: rgb(0, 0, 102);"><br>Picture:<br> </td> <td><input name="Picture" size="35" type="file"></td> </tr> </tbody> </table> <br> <input value="Enter Record" type="submit"></form><br><br><hr style="width: 100%; height: 2px;"><div style="text-align: left;"><a href="index.html"><img style="border: 0px solid ; width: 94px; height: 46px;" alt="Home" src="etc/Home_button.JPG"></a><br></div><hr style="width: 100%; height: 2px;"></div></div><div id="footer"><p style="text-align: left;"></p></div></div></body></html>[/code]Script_1.php[code]<?php$user="root";$host="localhost";$password="";$database = "employee index";mysql_connect("localhost", "root", "") or die(mysql_error());mysql_select_db("employee index") or die(mysql_error());$sqlquery = "INSERT INTO $employee details (Employee_ID,Surname,Forename,Job_title,Office_location,Telephone,Email,Expertise,Hobbies,DOB)VALUES ('$Employee_ID','$Surname','$Forename','$Job_title','$Office_location','$Telephone','$Email','$Expertise','$Hobbies','$DOB')";$result = mysql_query($query)or die (mysql_error());mysql_close();print "<html><body><center>";print "<p>Thank You - You have just entered this record<p>";print "Employee ID : $Employee_ID<br>";print "Surname : $Surname<br>";print "Forename : $Forename<br>";print "Job Titile : $Job_title<br>";print "Office Location : $Office_location<br>";print "Telephone : $Telephone<br>";print "Email : $Email<br>";print "Expertise : $Expertise<br>";print "Hobbies : $Hobbies<br>";print "DOB : $DOB<br>";print "</body></html>";?>[/code] Quote Link to comment Share on other sites More sharing options...
Gibbs Posted January 17, 2007 Share Posted January 17, 2007 Try echo $employee (to see if anything is printed).It doesn't look like you've set $employee to anything (which is the table your trying to write to). If true your trying to write to a table with no name. Quote Link to comment Share on other sites More sharing options...
jackie11 Posted January 17, 2007 Author Share Posted January 17, 2007 :-\Many Thanks for your replySorry, I'm really thick, not sure what you mean, when I said I was new to all this I really mean new, I've only been learning MYSQL and php for 3 days!! so a complete novice (Sorry to be a pain but could you explain what you mean) Thanks againJackie Quote Link to comment Share on other sites More sharing options...
Gibbs Posted January 17, 2007 Share Posted January 17, 2007 Im new too so don't expect too much ;DWhat i'm trying to say is that you have "INSERT INTO $employee". This means INSERT INTO $MYTABLE.You don't have $employee set to anything though. So it's trying to INSERT INTO (nothing).Try changing $employee with $database (which you have set to "employee index") Quote Link to comment Share on other sites More sharing options...
jackie11 Posted January 17, 2007 Author Share Posted January 17, 2007 :-\Hi I've tried changing it but it comes up as an error now!!not sure what to do next any suggestions!!Jackie Quote Link to comment Share on other sites More sharing options...
Gibbs Posted January 17, 2007 Share Posted January 17, 2007 Sorry yes I wasn't right.What's the name of the table your trying to put the information into? If you know the name above $sqlquery try this:$employee = "my table name".The start should then look like this:[code=php:0]<?php$user="root";$host="localhost";$password="";$database = "employee index";mysql_connect("localhost", "root", "") or die(mysql_error());mysql_select_db("employee index") or die(mysql_error());$employee = "My table name" // Change this$sqlquery = "INSERT INTO $employee (Employee_ID,Surname,Forename,Job_title,Office_location,Telephone,Email,Expertise,Hobbies,DOB)VALUES ('$Employee_ID','$Surname','$Forename','$Job_title','$Office_location','$Telephone','$Email','$Expertise','$Hobbies','$DOB')";[/code]Edit: Don't use spaces in variables/strings. $employee details won't work. Use $employee_details. Quote Link to comment Share on other sites More sharing options...
jackie11 Posted January 17, 2007 Author Share Posted January 17, 2007 HiTried that to, error message coming back! :-\The table I am trying to upload info to is called emplyee detailsbut I put that in the INSERT INTO Line so I completely confused!!Thanks for all your help but any more suggestions?Jackie Quote Link to comment Share on other sites More sharing options...
Gibbs Posted January 17, 2007 Share Posted January 17, 2007 Strange.$employee = "employee details";$sqlquery = "INSERT INTO $employee blah blah blah SHOULD work.Are your user, host and password correct?What's the error? Quote Link to comment Share on other sites More sharing options...
jackie11 Posted January 17, 2007 Author Share Posted January 17, 2007 Hi Still coming up - Query was emptyThe code I have changed it to is below just to clarify!Is this right?Would it have anything to do with register_globals being off (not that I'm sure what they are but I read something about them affecting variables?) [code]<?php$user="root";$host="localhost";$password="";$database = "employee index";mysql_connect("localhost", "root", "") or die(mysql_error());mysql_select_db("employee index") or die(mysql_error());$employee = "employee details";$sqlquery = "INSERT INTO $employee details (Employee_ID,Surname,Forename,Job_title,Office_location,Telephone,Email,Expertise,Hobbies,DOB)VALUES ('$Employee_ID','$Surname','$Forename','$Job_title','$Office_location','$Telephone','$Email','$Expertise','$Hobbies','$DOB')";$result = mysql_query($query)or die (mysql_error());mysql_close();print "<html><body><center>";print "<p>Thank You - You have just entered this record<p>";print "Employee ID : $Employee_ID<br>";print "Surname : $Surname<br>";print "Forename : $Forename<br>";print "Job Titile : $Job_title<br>";print "Office Location : $Office_location<br>";print "Telephone : $Telephone<br>";print "Email : $Email<br>";print "Expertise : $Expertise<br>";print "Hobbies : $Hobbies<br>";print "DOB : $DOB<br>";print "</body></html>";?>[/code] Quote Link to comment Share on other sites More sharing options...
Gibbs Posted January 17, 2007 Share Posted January 17, 2007 Change "INSERT INTO $employee details" to "INSERT INTO $employee" Quote Link to comment Share on other sites More sharing options...
jackie11 Posted January 17, 2007 Author Share Posted January 17, 2007 Hi no good error message back:Parse error: parse error, unexpected '(' in C:\Program Files\xampp\htdocs\Database\script_1.php on line 9 :'( :'( :'( :'( :'( :'(I feel like screamingAny other suggestions? Quote Link to comment Share on other sites More sharing options...
jackie11 Posted January 17, 2007 Author Share Posted January 17, 2007 HiCan anyone help with this I am coming up against a brick walleverything I'm trying is not workingPlease!!!!!ThanksJackie Quote Link to comment Share on other sites More sharing options...
Gibbs Posted January 17, 2007 Share Posted January 17, 2007 I've just been having a play around to see where you might have gone wrong.First of all when I try to create a database called "employee index" it created a database called "employee".Edit your database so that you are using underscores _ instead of spaces.So change "employee index" to "employee_index" and "employee details" to "employee_details".Then edit the PHP accordingly.Worth a try. Quote Link to comment Share on other sites More sharing options...
jackie11 Posted January 17, 2007 Author Share Posted January 17, 2007 HiI have tried that and changed database name to employee_index with the table now called employee, but still coming back with this problem, I have another search based query that is bring up the same problem the idea behind this is when someone types in surname and then submit it should display the required fields but this is also coming back - Query was empty so theres something wrong in who I'm requesting the dataThe code for this is:code in the html page:[code]<form name="form" action="search.php" method="get"> <input name="q" type="text"> <input name="Submit" value="Search" type="submit"></form>[/code]PHP Code:[code]$user="root";$host="localhost";$password="";$database = "employee_index";mysql_connect("localhost", "root", "") or die(mysql_error());mysql_select_db("employee_index") or die(mysql_error());$employee = "employee";$sqlquery = "SELECT * FROM `employee` WHERE Surname LIKE '%$search%'"; $result = mysql_query($query)or die (mysql_error()); $XX = "No Record Found"; while ($row = mysql_fetch_array($query)) { $variable1=$row["row_Employee_ID"]; $variable2=$row["row_Surname"]; $variable2=$row["row_forename"]; $variable2=$row["row_Job_title"]; $variable2=$row["row_Office_location"]; $variable2=$row["row_Telephone"]; $variable2=$row["row_Email"]; $variable2=$row["row_Expertise"]; $variable2=$row["row_Hobbies"]; $variable2=$row["row_DOB"]; $variable2=$row["row_Picture"]; print ("this is for $variable1, and this print the variable2 end so on..."); } //below this is the function for no record!! if (!$variable1) { print ("$XX"); } //end ?> [/code]Look can I just say thanks for all your help so far it really is appricatedThanks 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.