我有一个简单的表单(main.php),它将输入作为电话号码。客户:
<!DOCTYPE HTML>
<html>
<div style=margin:0 auto align=center >
<form action = "options.php" method = "get" />
<p> <h3>Enter Phone Number:</h3> <input type = "text" name =
"cust_phone" />
<p> <input type = "submit" value = "Submit" />
</form>
</div>
</html>
没有。在Oracle DB中检查输入,如果客户在“否”中。然后显示有关该客户的信息,否则通过电话号码添加新客户。 (options.php)
<!DOCTYPE HTML>
<html>
<body> Details of:<?php echo htmlentities($_GET["cust_phone"])."<br>";
$link = oci_connect('hd', 'hd', 'localhost/mydb');
if(!$link)
{
$e = oci_error();
exit('Connection Error' . $e['message']);
}
$query = "select cust_id from customer where cust_phone = :ph_bv";
$stid = oci_parse($link,$query);
$ph = htmlentities($_GET["cust_phone"]);
oci_bind_by_name($stid, ':ph_bv', $ph);
oci_execute($stid);
$row = oci_fetch_array($stid, OCI_ASSOC);
if(!$row)
{
exit("Person Not Found");
}
$cust_id = $row["ID"];
oci_free_statement($stid);
?>
<table border = "black" />
<tr>
<th> ADDRESS </th>
<th> AREA </th>
</tr>
<?php
$query1 = "select a.address, a.area from customer c
join customer_address ca on c.cust_id = ca.cust_id
join address a on a.address_id = ca.address_id where cust_id =
:id_bv";
$stid1 = oci_parse($link, $query1);
oci_bind_by_name($stid1, ":id_bv", $cust_id);
oci_execute($stid1);
while($row = oci_fetch_array($stid1))
{
echo "<tr><td>" . htmlentities($row["ADRESS"]) . "</td>";
echo "<td>" . htmlentities($row["AREA"]) . "</td></tr>";
}
oci_free_statement($stid1);
oci_close($link);
?>
</table>
</body>
</html>
代码的第一部分工作正常,它显示消息&#34; Person Not Found&#34;。但是第二部分给出了错误: 详情:9711210000
( ! ) Notice: Undefined index: ID in
E:\xampp\htdocs\myfiles\options.php on line 24
Call Stack
# Time Memory Function Location
1 0.0013 137104 {main}( ) ...\options.php:0
ADDRESS AREA
( ! ) Warning: oci_execute(): ORA-00918: column ambiguously defined in
E:\xampp\htdocs\myfiles\options.php on line 38
Call Stack
# Time Memory Function Location
1 0.0013 137104 {main}( ) ...\options.php:0
2 0.0400 139336 oci_execute ( ) ...\options.php:38
( ! ) Warning: oci_fetch_array(): ORA-24374: define not done before
fetch or execute and fetch in E:\xampp\htdocs\myfiles\options.php on line
39
Call Stack
# Time Memory Function Location
1 0.0013 137104 {main}( ) ...\options.php:0
2 0.0418 139336 oci_fetch_array ( ) ...\options.php:39
我有两个问题: 1.我想在我的数据库中添加一个新客户,而不是找不到#34; 2.如何解决这些错误? 我是PHP的新手,这只是我的第一个代码。任何帮助表示赞赏。
答案 0 :(得分:0)
$ row没有记录,因此您无法访问$ row [&#34; ID&#34;]所以首先检查记录是否存在然后只访问数据。
第二个问题在于您的查询,cust_id字段位于两个表中,因此在编写查询时将其与别名一起使用。
尝试以下代码: -
<!DOCTYPE HTML>
<html>
<body> Details of:<?php echo htmlentities($_GET["cust_phone"])."<br>";
$link = oci_connect('hd', 'hd', 'localhost/mydb');
if(!$link)
{
$e = oci_error();
exit('Connection Error' . $e['message']);
}
$query = "select cust_id from customer where cust_phone = :ph_bv";
$stid = oci_parse($link,$query);
$ph = htmlentities($_GET["cust_phone"]);
oci_bind_by_name($stid, ':ph_bv', $ph);
oci_execute($stid);
$row = oci_num_rows($stid);
$cust_id ='';
if($row>0)
{
$rows = oci_fetch_array($stid, OCI_ASSOC);
$cust_id = $rows["ID"];
oci_free_statement($stid);
exit("Person Not Found");
}
?>
<table border = "black" />
<tr>
<th> ADDRESS </th>
<th> AREA </th>
</tr>
<?php
$query1 = "select a.address, a.area from customer c
join customer_address ca on c.cust_id = ca.cust_id
join address a on a.address_id = ca.address_id where c.cust_id =
:id_bv";
$stid1 = oci_parse($link, $query1);
oci_bind_by_name($stid1, ":id_bv", $cust_id);
oci_execute($stid1);
while($row = oci_fetch_array($stid1))
{
echo "<tr><td>" . htmlentities($row["ADRESS"]) . "</td>";
echo "<td>" . htmlentities($row["AREA"]) . "</td></tr>";
}
oci_free_statement($stid1);
oci_close($link);
?>
</table>
</body>
</html>
答案 1 :(得分:0)
<!DOCTYPE HTML>
<html>
<body> Details of: <?php echo htmlentities($_GET["cust_phone"]) . "<br>";
$link = oci_connect('hd','hd', 'localhost/mydb');
if(!$link) {
$e = oci_error();
exit('Connection error ' . $e['message']);
}
$ph = htmlentities($_GET["cust_phone"]);
$q1 = "select CUST_ID from customer where CUST_PHONE = :bv_ph";
$q1parse = oci_parse($link, $q1);
oci_bind_by_name($q1parse, ':bv_ph', $ph);
oci_execute($q1parse);
oci_fetch($q1parse);
$res = oci_result($q1parse, 'CUST_ID');
if(!$res) {
exit("Person Not Found");
}
?>
<table border = "black">
<tr>
<th> ADDRESS </th>
<th> AREA </th>
</tr>
<?php
$q2 = "select A.ADDRESS, A.AREA from customer c
join customer_address ca on C.CUST_ID = CA.CUST_ID
join address a on A.ADDRESS_ID = CA.ADDRESS_ID where C.CUST_ID = :id_bv";
$q2parse = oci_parse($link, $q2);
oci_bind_by_name($q2parse, ':id_bv', $res);
oci_execute($q2parse);
while($row = oci_fetch_array($q2parse)) {
echo "<tr><td>" . htmlentities($row["ADDRESS"]) . "</td>";
echo "<td>" . htmlentities($row["AREA"]) . "</td></tr>";
}
oci_free_statement($q2parse);
oci_close($link);
?>
</table>
</body>