0

I m trying to insert user's check in value into db. For this i call the function and set the hidden field's value and than trying to submit the form but here after the form is submiteed hiden field's value is reset .

HTML Code

<form name="checkinout" action="logindetails.php" method="post" enctype="multipart/form-data" id="checkinout">
<table class="login-detaills" width="100%"><thead><th></th><th>Check In</th><th>Check Out</th><th>Hours</th></thead>
<tr><td></td><td></td><td></td><td></td></tr>
</table>
</fieldset>
<table>
<tr><td><input type="button"  onClick="call()" value="checkin"></button></td><td><input type="button" id="logout" onclick="call2();" value="Check Out" ></td></tr>
<tr><td><input type="hidden" id="checkin" name="checkin"></td><td><input type="hidden" id="checkout" name="checkout"></td></tr>
</table>
</form>

Javascript

function call(){
$('#checkin').val("checkin");
$('#checkinout').submit();
}
function call2(){
$('#checkout').val("checkout"); 
$('#checkinout').submit();
}

PHP CODE

 if(isset($_POST['checkinout']) ){
    if(isset($_POST['checkin']) && $_POST['checkin']=='checkin'){
    $sql = "INSERT INTO attend (loginout,log_type,fk_userid) VALUES ('".TODAY_DATETIME."','I','".$_SEESION['user_id']."')";     
}elseif(isset($_POST['checkout']) && $_POST['checkout']=='checkout'){
    $sql = "INSERT INTO attend (loginout,log_type,fk_userid) VALUES ('".TODAY_DATETIME."','O','".$_SEESION['user_id']."')";     

}   
$stmt = $class->dbh->prepare($sql);
$stmt->execute();
$res = $stmt->fetch(PDO::FETCH_ASSOC);
}

first of all its not satisfied this if(isset($_POST['checkinout'])

user3887375
  • 51
  • 1
  • 1
  • 4
  • Have you watched the request/response in your browser's developer tools? Are you getting any errors? – Jay Blanchard Jul 31 '14 at 13:45
  • call() function sould look like this: `function call(){ $('#checkin').val("checkin"); $('#checkinout').submit(); }` – MaK Jul 31 '14 at 13:51
  • add name attributes to your inputs so you can get them with _POST – MaK Jul 31 '14 at 13:52
  • you should consider removing the hidden inputs and use two submit buttons with your form take a look [here](http://stackoverflow.com/questions/547821/two-submit-buttons-in-one-form) – MaK Jul 31 '14 at 13:55

4 Answers4

2

<input type="hidden" id="checkout"> has no name attribute, so even if you give it a value, it won't be a successful control and won't be submitted.

If you want $_POST['checkout'] to be populated, you need an element with name="checkout".

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

You dont have name attribute defined in you code ..For using $_POST['checkout'] you must have <input type="hidden" id="checkout" name="checkout">

Avinash Babu
  • 6,171
  • 3
  • 21
  • 26
0

It looks like you're checking if the post value $_POST['checkinout'] is set, but I dont see that form control anywhere. The only controls I see are these:

<input type="button"  onClick="call()" value="checkin"></button>
<input type="button" id="logout" onclick="call2();" value="Check Out" >

<input type="hidden" id="checkin" >
<input type="hidden" id="checkout">

Like @Quentin said, they don't have a name attribute so they won't show up in the $_POST array after submission in any event, so that's another thing you must fix.

I think you're most likely assuming that, since the form id is checkinout, that the index $_POST['checkinout'] will be set upon form submission. This is not the case; only form controls (inputs, selects, checkboxes, buttons, etc.) will populate data inside of $_POST and the key inside of the $_POST array will be set equal to the value of the name attribute of the form control.

Jeff Lambert
  • 24,395
  • 4
  • 69
  • 96
0

you really should consider using two submit button with your from, take a look at this question, and remove the hidden input and all the unnecessary js code

Community
  • 1
  • 1
MaK
  • 596
  • 4
  • 23