0
每次當我運行下面的PHP代碼我得到的輸出錯誤使用Oracle序列在PHP
預訂確認!恭喜。您的預訂ID爲:6
預訂成功。
該bookingid是一個序列,然後我得到的預訂ID形式插入的值來獲得序列的當前值。所以我不知道我做錯了什麼。
<html><body>
<?php
$con = oci_connect("system", "password", "localhost/XE");
if (!$con) {
$m = oci_error();
exit('Connect Error ' . $m['message']);
}
$thid = $_GET["hid"];
$trno = $_GET["rno"];
$tgid = $_GET["gid"];
$sd = $_GET["sdate"];
$ed = $_GET["edate"];
$dchange = "ALTER SESSION SET NLS_DATE_FORMAT= 'YYYY-MM-DD'";
$stid1 = oci_parse($con,$dchange);
oci_execute($stid1);
$c1 = "SELECT * FROM B WHERE HOTELID = '$thid' AND ROOMNO = '$trno' AND ((STARTDATE < '$sd' AND ENDDATE > '$sd') or (STARTDATE < '$ed' AND ENDDATE > '$ed') or (STARTDATE >= '$sd' AND ENDDATE <= '$ed'))";
$c2 = oci_parse($con, $c1);
oci_execute($c2);
$row = oci_fetch_row($c2);
if(!$row)
{
$temp = "INSERT INTO B VALUES(bno.nextval,'$thid','$trno','$tgid','$sd','$ed')";
$stid = oci_parse($con,$temp);
oci_execute($stid);
oci_free_statement($stid);
//$c7 = "SELECT bookid FROM B WHERE HOTELID = '$thid' AND ROOMNO = '$trno' AND GUEStID = '$tgid' AND STARTDATE = '$sd' AND ENDDATE = '$ed'";
//printf("<h3>Booking Confirmed! Congatulation. </h3>") ;
**$c8 = oci_parse($con, "SELECT MAX(BOOKID) FROM B");
oci_execute($c8);
printf("<h3>Booking Confirmed! Congratulation. Your Booking Id is: %u</h3>", $c8);**
}
else
printf("<h3>Booking already exist. </br>Please try with another search.</h3>");
?>
</n> <form action="index.php"><input type="submit" value="BACK" />
</form>
</BODY>
我沒有任何平行預訂..但仍然我沒有得到正確的預訂ID。首先,我嘗試了bno.currval,但即便如此,也沒有嘗試過其他方式。但輸出沒有變化。在我試圖檢索bookingid的那個部分存在一些問題。因爲如果我檢查我的預訂表,它是正確插入的。 – 2013-03-19 22:15:10
@HarshShah雖然maxi(bookid)的oci_fetch_row是哪裏?你似乎正在打印語句句柄ID'$ c8'與提取的行值 – DazzaL 2013-03-19 22:17:46
謝謝Dazzal找出我錯在哪裏。感謝它的工作。 – 2013-03-19 22:30:53