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

Link to comment
Share on other sites

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);

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.