Jump to content

Form Help!


jackie11

Recommended Posts

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

Thanks

Jackie


Form.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">New
Employee 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);">Employee
ID:</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);">Job
Title:</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);">Office
Location:</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]
Link to comment
Share on other sites

:-\
Many Thanks for your reply

Sorry, 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 again

Jackie

Link to comment
Share on other sites

Im new too so don't expect too much  ;D

What 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")
Link to comment
Share on other sites

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.
Link to comment
Share on other sites


Hi Still coming up - Query was empty


The 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]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

Hi

I 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 data

The 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 appricated

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