Displaying Information based on entered value in PHP with Oracle Database 11g R2 [message #663238] |
Fri, 26 May 2017 08:01 |
|
kaos.tissue
Messages: 94 Registered: May 2017
|
Member |
|
|
I have a simple form (main.php) which takes input as a Phone no. of the customer:
<!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>
The no. entered is checked in the Oracle DB and if a customer is present with the no. then information regarding that customer is displayed else a new customer is added with the phone no. (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>
The first part of the code works fine and it displays the message "Person Not Found". However the second part gives error:
Details of: 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
I have two questions:
1. Instead of "person not found", I want to add a new customer in my DB?
2. How to resolve these errors? I am new to PHP and this is just my first code. Any help appreciated.
|
|
|
|
|
|
|
|
Re: Displaying Information based on entered value in PHP with Oracle Database 11g R2 [message #663261 is a reply to message #663260] |
Sat, 27 May 2017 03:52 |
|
kaos.tissue
Messages: 94 Registered: May 2017
|
Member |
|
|
1 <!DOCTYPE HTML>
2 <html>
3 <body> Details of:<?php echo htmlentities($_POST["cust_phone"])."<br>";
4
5 $link = oci_connect('hd', 'hd', 'localhost/mydb');
6 if(!$link)
7 {
8 $e = oci_error();
9 exit('Connection Error' . $e['message']);
10 }
11 $query = "select cust_id from customer where cust_phone = :ph_bv";
12 $stid = oci_parse($link,$query);
13 $ph = htmlentities($_POST["cust_phone"]);
14 oci_bind_by_name($stid, ':ph_bv', $ph);
15 oci_execute($stid);
16 $row = oci_fetch_array($stid, OCI_ASSOC);
17 if(!$row)
18 {
19 exit("Person Not Found");
20 }
21 $cust_id = $row["ID"];
22 oci_free_statement($stid);
23
24 <table border = "black" />
25 <tr>
26 <th> ADDRESS </th>
27 <th> AREA </th>
28 </tr>
29 <?php
30 $query1 = "select a.address, a.area from customer c
31 join customer_address ca on c.cust_id = ca.cust_id
32 join address a on a.address_id = ca.address_id where c.cust_id = :id_bv";
33 $stid1 = oci_parse($link, $query1);
34 oci_bind_by_name($stid1, ":id_bv", $cust_id);
35 oci_execute($stid1);
36 while($row = oci_fetch_array($stid1))
37 {
38 echo "<tr><td>" . htmlentities($row["ADRESS"]) . "</td>";
39 echo "<td>" . htmlentities($row["AREA"]) . "</td></tr>";
40 }
41 oci_free_statement($stid1);
42 oci_close($link);
43 ?>
44 </table>
45 </body>
46 </html>
The error:
Details of:981115000
( ! ) Notice: Undefined index: ID in E:\xampp\htdocs\myfiles\options.php on line 21
Call Stack
# Time Memory Function Location
1 0.0009 138616 {main}( ) ...\options.php:0
ADDRESS AREA
[Updated on: Sat, 27 May 2017 03:58] Report message to a moderator
|
|
|
|
|
|
|
Re: Displaying Information based on entered value in PHP with Oracle Database 11g R2 [message #663284 is a reply to message #663283] |
Sun, 28 May 2017 05:56 |
|
kaos.tissue
Messages: 94 Registered: May 2017
|
Member |
|
|
I like you guys. I did it.
<!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>
</html>
|
|
|