Ok so I have been working on this all day but cant get it.
I want to add an Employee ID to an Employee Table....I got this much...But first I need to check if that ID exists already. How can I do this, here is my code:
<?php
session_start();
require_once 'php_includes.php';
//Make sure logged in
checkLogin();
///////////////////////////////////
//This is only for manager only pages. Verifies that the person viewing this page is a manager.
sqlConnect();
$con=sqlConnect();
$sql = 'select ManagerID from Employee where EmployeeID = ' . $_SESSION['tmsUserID'];
// Perform Query
$sqlresult = sqlQuery($sql);
$result = mysql_result($sqlresult, 0, 0);
if( $_SESSION['tmsUserID'] != $result )
{
$_SESSION['errorMessage'] = "Access denied";
include("error.php");
exit();
}
////////////////////////
else
{
//Makes sure that the userId and Session User Id are not the same because only managers have same user ID and same ManagerID
if ($_SESSION['tmsUserID'] == $_POST['userid'])
{
exit("<p>Illegal Action! Please choose a different Employee ID <br> Click <a href=\"addemployee.php\">here</a> to go back.</p>");
}
else
{
//Checks if the user has entered values in all fields
if(empty($_POST['userid']) ||empty($_POST['password']))
{
exit("<p>You must enter values in all fields of the Add Employee form! <br> Click <a href=\"addemployee.php\">here</a> to go back.</p>");
}
///////////////
/////THIS IS WHERE I NEED HELP!!!! after this else I need to check if the employeeID exists or not. IF it does then ask the user to go back, if it does not exists then perform $sql2 query.
//////////////////////////////////////////////////
else
{
mysql_select_db("titans", $con);
//adds employee to database
$sql2="INSERT INTO Employee (employeeID, employeePassword, ManagerID)
VALUES
('$_POST[userid]','$_POST[password]','$result')";
if(!sqlQuery($sql2))
{
include("error.php");
exit();
}
else
{
echo "Employee added.<br> <p> Click <a href=\"addemployee.php\">here</a> to add another employee.</p> ";
//Close DB
sqlExit();
}
}
}
}
?>
HELP!!!