Jump to content

[SOLVED] Check Before Insert...


savagenoob

Recommended Posts

I am creating a timeclock system and want to check to make sure they are not clocking in when they are already clocked in... how do i lookup status of the employee before inserting on this:

 

<?php	
$employee = $_SESSION['SESS_MEMBER_ID'];
$inout = $_POST['punch'];
$query = "INSERT INTO timeclock SET Employee='$employee', InOut='$inout'";
$result = mysql_query($query);
echo mysql_error();
echo $query;
mysql_free_result($result);
?>

Link to comment
https://forums.phpfreaks.com/topic/141012-solved-check-before-insert/
Share on other sites

Yeah, I am getting it to work first but 'punch' doesnt come from user text, just a menu that says out, in, lunch, break and submit.

Ok, I tried this:

<?php
$employee = $_SESSION['SESS_MEMBER_ID'];
$inout = $_POST['punch'];
$fquery = "SELECT clock, Time FROM timeclock WHERE employee = '$employee' ORDER BY ID DESC LIMIT 1";
$fresult = mysql_query($fquery);
if ($fresult[0] != $inout)
{

$query = "INSERT INTO timeclock SET Employee='$employee', clock='$inout'";
$result = mysql_query($query);
echo mysql_error();
echo "<meta http-equiv=refresh content=\"0; URL=time.php\">";
mysql_free_result($result);
}
else
{
	echo "You selected same status...";
}
?>

But it still lets you submit 'In' if your already clocked in... Im such a noob.

It still comes from the client.  Know how hard HTML is to change?  I can do it in Firefox with Firebug without even saving the page ;p.

 

 

$fresult = mysql_query($fquery);

  if ($fresult[0] != $inout)

  {

 

 

$fresult would be a resource, not an array.  You would want to pull the data from the resource, with a function like mysql_fetch_row or mysql_fetch_assoc.  (In this situation, mysql_result might actually be faster.)

 

Anyway, you would want to do:

 

$fresultq = mysql_query($fquery);

$fresult = mysql_fetch_row($fresultq);

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.