Oracle,php - 在表单中添加操作

时间:2016-08-12 07:44:07

标签: php html oracle

我试图让这个按钮检查通过文本框传递的员工ID是否存在于Oracle数据库中并依赖于结果 - 在'之后显示是或否:

enter image description here

但我完全不知道如何。我试图以一种形式制作一个表格:

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

但是没有成功,因为它无法完成。 有什么建议? 编辑:

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";
    }

    ?>

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>

但是ajax不希望将参数传递给check.php(未定义的错误),如果我设置var empID = whatever number则总是让我拥有&#39;。

1 个答案:

答案 0 :(得分:1)

1)嵌套<form> 允许。

2)检查员工是否存在。使用 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";
}
?>
相关问题