I want to try to setup something where if user already submitted a dept key and current date it will stop the record from being inserted. It will give out an error saying duplicate record entered try again.
Here is part of my insert page but it is not working
$stmt= $db->prepare("INSERT INTO tbl_lighting(Department,
areaCode, offtime, gytime, ftime, ini,
sat_ob_department, sat_ib_department,
sat_ob_onTime,sat_ib_onTime,
sat_ob_offTime, sat_ib_offTime,
ob_signature,ib_signature,
deptkey, comments,ib_comments,ob_comments,Requestdate
) Values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)WHERE NOT EXISTS
(SELECT * FROM tbl_lighting where deptkey = $deptkey AND Requestdate= CAST(GETDATE() AS DATE)");
$stmt->bindParam(1, $_POST["Department"]);
$stmt->bindParam(2, $_POST["areaCode"]);
$stmt->bindParam(3, $_POST["offtime"]);
$stmt->bindParam(4, $_POST["gytime"]);
$stmt->bindParam(5, $_POST["ftime"]);
$stmt->bindParam(6, $_POST["ini"]);
$stmt->bindParam(7, $_POST["sat_ob_department"]);
$stmt->bindParam(8, $_POST["sat_ib_department"]);
$stmt->bindParam(9, $_POST["sat_ob_onTime"]);
$stmt->bindParam(10, $_POST["sat_ib_onTime"]);
$stmt->bindParam(11, $_POST["sat_ob_offTime"]);
$stmt->bindParam(12, $_POST["sat_ib_offTime"]);
$stmt->bindParam(13, $_POST["ob_signature"]);
$stmt->bindParam(14, $_POST["ib_signature"]);
$stmt->bindParam(15, $_POST["deptkey"]);
$stmt->bindParam(16, $_POST["comments"]);
$stmt->bindParam(17, $_POST["ib_comments"]);
$stmt->bindParam(18, $_POST["ob_comments"]);
$stmt->bindParam(19, $_POST["Requestdate"]);
$stmt->execute();
Here is my submit form
<form action = "insert_process.php" onsubmit="return validateForm()" name="form" id="form" method ="post" class="style1">
<table align="center" id="tfhover" class="tftable" border="1">
<br><br>
<tr>
<td colspan="7"><h1 align="center">Lighting Schedule Form</h1></td>
</tr>
<tr>
<th>Department</th><th style="width: 75px">Area Code</th><th style="width: 144px">Off Time</th><th>Grave Yard On Time</th><th>First Shift OnTime</th><th width="125px">Comments Or Date By</th><th>Initials</th></tr>
<tr>
<!--First row accross on the table-->
<td><select name="Department" id="Department" >
<option value ="">Please select ...</option>
<option value ="Upstairs Hang East">Upstairs Hang East</option>
<option value ="Upstairs Hang West">Upstairs Hang West</option>
<option value ="RDR">RDR</option>
</select></td>
<td style="width: 75px"><input id="areaCode" name="areaCode" onkeydown="return false;" type="text"/></td>
<td style="width: 144px"><input class="offtime" id="offtime" name="offtime" type="text" /></td>
<td><input id="gytime" name="gytime" type="text"></td>
<td><input id="ftime" name="ftime" type="text" ></td>
<td><input id="comments" name="comments" type="text"></td>
<td><input id="ini" name="ini" type="text" style="width: 68px" /></td>
</tr>
<input id="deptkey" name="deptkey" onkeydown="return false;" type="hidden"/>
<!--end-->