gpt4 book ai didi

php - 如何修复错误 "PHP Warning: oci_execute(): ORA-00932: inconsistent datatypes: expected DATE got NUMBER"?

转载 作者:行者123 更新时间:2023-12-03 08:18:02 26 4
gpt4 key购买 nike

我在 php 中有一个自动填充当前日期列。它进一步进入 oracle 数据库。表单提交后,我收到上述错误。
这是代码:

<form class="cmxform" action ='functions/processform.php' id="Form1" method="post">
<legend> Add Member</legend>
<label for="addname">Select*</label>
<select class="form-control" name="school" id="school">
<?php
$names = $getnames->getnames();
oci_execute($names, OCI_DEFAULT);
while ($row = oci_fetch_array($names, OCI_ASSOC+OCI_RETURN_NULLS)) {
echo '<option value="' . $row['NAME'] . '">' . $row['NAME']. '</option>';
}
?>
</select>
<div class="form-row">

<div class="form-group col-md-4">
<label for="fName">First Name* </label>
<input type="text" class="form-control" id="fName" name="fName" required>
</div>
<div class="form-group col-md-4">
<label for="mName">Middle Name</label>
<input type="text" class="form-control" id="mName" name="mName">
</div>
<div class="form-group col-md-4">
<label for="lName">Last Name* </label>
<input type="text" class="form-control" id="lName" name="lName" required>
</div>

<div class="form-row">
<input type="radio" id="p" name="paidunpaid" value="p">
<label for="paid">Paid</label><br>
<input type="radio" id="female" name="paidunpaid" value="u">
<label for="unpaid">Unpaid</label><br>
</div>

<div class="form-row">
<div class="form-group">
<label for="date">Date</label>
<input name="date" id="date" required type="text" value="<?php echo date('d/m/Y'); ?>" />
</div>
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="Id">Id </label>
<input type="text" class="form-control" id="Id" name="Id">
</div>
</div>
<button class="btn btn-info btn-primary" type="submit">Add Role</button>
进程表单.php
$fName = filter_input(INPUT_POST, "fName", FILTER_SANITIZE_STRING);
$lName = filter_input(INPUT_POST, "lName", FILTER_SANITIZE_STRING);
$mName = filter_input(INPUT_POST, "mName", FILTER_SANITIZE_STRING);
$id = filter_input(INPUT_POST, "Id", FILTER_SANITIZE_STRING);
$school = filter_input(INPUT_POST, "school", FILTER_SANITIZE_STRING);
$paidunpaid = filter_input(INPUT_POST, "paidunpaid", FILTER_SANITIZE_STRING);
$dt = filter_input(INPUT_POST, "dt", FILTER_SANITIZE_STRING);
$dbUser = "xxxx";
$dbPass = "xxxx";
$dbConn = "(DESCRIPTION = (ADDRESS = (PROTOCOL=TCP)(HOST=xxxx)(PORT=1521))(CONNECT_DATA=(SID=xxxx)))";
$conn = oci_connect($dbUser, $dbPass, $dbConn);
$sql =oci_parse($conn, "INSERT INTO person (LastName, FirstName, MiddleName, ID, Primaryschool, Paidunpaidposition,date)
VALUES(:lName,:fName,:mName, :id, :school, :paidunpaid, :date)");
oci_bind_by_name($sql, ':dt', $dt);
oci_bind_by_name($sql, ':fName', $fName);
oci_bind_by_name($sql, ':lName', $lName);
oci_bind_by_name($sql, ':mName', $mName);
oci_bind_by_name($sql, ':id', $id);
oci_bind_by_name($sql, ':school', $school);
oci_bind_by_name($sql, ':paidunpaid', $paidunpaid);
$result = oci_execute($sql);
if ($result) {
echo
'<script >
alert("Thank you for registration.");
window.location = "http://google.com/";
</script>';

return true;
} else {
echo '
<script>
alert("Error, please try submitting again. Error code 1");
window.history.back();
</script>';
return false;
}
我已经更新了整个代码,因为一个错误会导致另一个错误。我是 php 新手,任何帮助都将不胜感激。我正在写这篇文章,因为我不能仅仅因为一个错误就发布这么多代码。需要一些文本来更新其余代码。先感谢您。

最佳答案

您正在尝试绑定(bind)字符串而不是日期数据类型。
修改如下

$sql =oci_parse($conn, "INSERT INTO person (date)                              
VALUES(to_date(:dt,'dd/mm/yyyy'))");
oci_bind_by_name($sql, ':dt', $date);

关于php - 如何修复错误 "PHP Warning: oci_execute(): ORA-00932: inconsistent datatypes: expected DATE got NUMBER"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63583560/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com