Michał M Michał M - 3 months ago 12
HTML Question

Oracle, php - add action in form

I'm trying to make this button checking if Employee ID passing via textbox exsits in Oracle Database and depend on result - show YES or NO after ':'.

enter image description here

But i have absolutely no idea how. I tried to make a form in a form:

<form action="addemp.php" method="POST">
<table>
<tr>
<td>Employee ID: </td>
<td><input type="text" name="empid" size=1/>
<form action="check.php" method="POST">
<input type="submit" name="check" value="Check?"> :
</form>


But no success since It can not be done.
Any suggestions?
EDIT:

check.php

<?php

$conn = oci_connect('hr', 'hr', 'hr');
$stid = oci_parse($conn, "select count(*) from employees where employee_id=TO_NUMBER(".$_GET['idprac'].")");
oci_execute($stid);
$result = oci_num_rows($stid);
// Use this $empId and check in query.

if($result==1){
echo "free";
} else
{
echo "owned";
}

?>


code in index.html

<td><input type="text" name="idprac" size=1/>
<input type="button" name="check" class='checkEmp' value="Check?"> : <span class='showResult'></span>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$('.checkEmp').click(function(){
var empId= $('#idprac').val();
$.ajax({url:"check.php?idprac="+empId,cache:false,success:function(result){
$('.showResult').html(result);
}});
});
</script>


But ajax does not want to pass parameter to check.php (undefined error) and if i set
var empID = whatever number
gives me always 'owned'.

Answer

1) Nested <form> are NOT allowed.

2) To check employee exist or not. Use Ajax.

<form action="addemp.php" method="POST">
  <table>
    <tr>
      <td>Employee ID: </td>
      <td>
        <input type="text" id='empId' name="empid" size=1/> 
        <input type="button" name="check" class='checkEmp' value="Check?"> : <span class='showResult'></span>
      </td>
    </tr>
  </table>
</form>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
  $('.checkEmp').click(function(){
    var empId= $('#empId').val();
    $.ajax({url:"check.php?empId="+empId,cache:false,success:function(result){
      $('.showResult').html(result);
    }});
  });
</script>

check.php

<?php
$empId = $_GET['empId'];

// Use this $empId and check in query.

if(employee id is available){
  echo "Yes";
} else {
  echo "No";
}
?>