使用Oracle数据库11g R2在PHP中显示基于输入值的信息

使用Oracle数据库11g R2在PHP中显示基于输入值的信息,php,oracle11g,Php,Oracle11g,我有一个简单的表单(main.php),它将输入作为客户的电话号码: <!DOCTYPE HTML> <html> <div style=margin:0 auto align=center > <form action = "options.php" method = "get" /> <p> <h3>Enter Phone Number:</h3>

我有一个简单的表单(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>
我有两个问题: 1.我想在数据库中添加一个新客户,而不是“找不到人”? 2.如何解决这些错误?
我是PHP新手,这只是我的第一段代码。感谢您的帮助。

$row没有该记录,因此您无法访问$row[“ID”],因此,首先检查记录是否存在,然后仅访问数据

第二个问题是您的查询,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>

详情如下:
地址
地区

详情如下:
地址
地区

它对现有电话号码给出了错误的结果。\u否。它不会为现有电话号码返回任何行。即使对于现有pnoe编号,“oci_num_rows”=0。请告诉我如何将CUST_ID的值存储在第一次查询检索到的变量中,即“从客户处选择CUST_ID,其中CUST_phone=:ph_bv”。所有输入的结果仍然相同。查询在sql*plus中运行良好。我想问一件事,什么是$rows[“ID”]。它有什么价值?它是来自我的数据库的列名,因为我在数据库中的列是“cust_id”。Yes id应该是列名。我以为这是专栏,所以更新后的代码没有改变,我知道了。我发布了一个答案,我认为它是正确的。过来看。
      ( ! ) 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
    <!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>
     <!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>