INSERT query not working
Posted: Tue Apr 13, 2010 7:33 pm
hi guys im not quite sure whats going wrong but my mysql insert query aint working, im trying to insert data for a job into my job table but it just keeps redirecting and until i added the error handler bit at the bottom it didnt say why, iv got a feeling its the query bit but cant see why iv checked over the variables and table names a few times but they seem right. the reason i think its the query is because it redirects me to the previous page with the error i set up if the query doesnt work anyway heres my code. thanks in advanced for any help
Code: Select all
<?PHP //error_reporting(E_ALL);
//start the session
session_start();
//check to make sure the session variable isn't registered
if(!session_is_registered('EmpID')){
//the session variable isn't registered, send them back to the login page
header( "Location: JMSystemLogin.php" );
}
$EmpID = $_SESSION['EmpID'];
include ('connect_db.php');
$JobID = $_POST['JobID'];
$UnitID = $_POST['UnitID'];
$OpndBy = $_POST['OpenedBy'];
$Assign = $_POST['AssignTo'];
$OpnDate = $_POST['OpenedDate'];
$WrkArea = $_POST['WorksArea'];
$Priority = $_POST['Priority'];
$Desc = $_POST['Description'];
$Comments = $_POST['Comments'];
if (!isset($JobID) || !isset($UnitID) || !isset($OpndBy) || !isset($Assign) || !isset($OpnDate) || !isset($WrkArea) || !isset($Priority) || !isset($Desc))
{
$error = "Please fill out all of the starred fields";
header( "Location: AddNew.php?error=$error" );
}
if (empty($JobID) || empty($UnitID) || empty($OpndBy) || empty($Assign) || empty($OpnDate) || empty($WrkArea) || empty($Priority) || empty($Desc))
{
$error = "Please fill out all of the starred fields";
header( "Location: AddNew.php?error=$error" );
}
if ($Priority==1)
{
$TargetDate = date ('d/m/Y', strtotime('today +1 days'));
}
else if ($Priority==2)
{
$TargetDate = date ('d/m/Y', strtotime('today +2 days'));
}
else if ($Priority==3)
{
$TargetDate = date ('d/m/Y', strtotime('today +3 days'));
}
else
{
$TargetDate = date ('d/m/Y', strtotime('today +4 days'));
}
$insert = "INSERT INTO Job (JobID, Client_ClientID Employee_EmployeeID, Units_UnitID, JobDescription, JobOpenedBy, Priority, DateSubmitted, TargetDate, Comments) VALUES ('$JobID', '$WrkArea', '$EmpID', '$UnitID', '$Desc', '$OpndBy', '$Priority', '$OpnDate', '$TargetDate', '$Comments')";
if (!mysql_query($insert))
{
$error = "Insert Failed";
header( "Location: AddNew.php?error=$error" );
}
else
{
header ("location: Jobs.php");
}
?>