Oracle,php - 在表单中添加操作
Oracle, php - add action in form
我正在尝试让此按钮检查通过文本框传递的员工 ID 是否存在于 Oracle 数据库中并取决于结果 - 在“:”后显示“是”或“否”。
但我完全不知道怎么做。我尝试以表格形式制作表格:
<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
总是给我 'owned'.
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";
}
?>
我正在尝试让此按钮检查通过文本框传递的员工 ID 是否存在于 Oracle 数据库中并取决于结果 - 在“:”后显示“是”或“否”。
但我完全不知道怎么做。我尝试以表格形式制作表格:
<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
总是给我 'owned'.
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";
}
?>