-1

Code:

<?php

include('core/settings.php');
include('core/connection.php');

function getInvoice($n, $conn) 
{ 
   $stid = oci_parse($conn, '

     SELECT InvoiceNo FROM Orders WHERE OrderNo = $n

   ');
   oci_execute($stid);

   $result = oci_fetch_array($stid, OCI_BOTH);
   echo $result;
} 

getInvoice(1050505);

?>

I am not shown the results of getInvoice when visiting this page. The manual SQL works ok. Is there a problem here in the PHP that I am using?

Edit 1: If there is a simpler method to do this then please suggest it. The SQL result is a simple number for example:

InvoiceNo
---------

1050505

Edit 2: I have updated functions.php and put it below.

<?php

function getInvoice($n) 
{ 
   include('connection.php');

   $stid = oci_parse($conn, 'SELECT InvoiceNo FROM Orders WHERE OrderNo = '.$n);
   oci_execute($stid);

   $row = oci_fetch_array($stid, OCI_BOTH);
   echo $row['0'];
} 

?>

The getInvoice works if I use it within that file, but when I try and use this in another file, it doesn't return anything.

<? php

  include('core/functions.php');

  getInvoice(1050505);

?>
user2656114
  • 949
  • 4
  • 18
  • 35

2 Answers2

2

Make a change in SQL query as '' doesn't recognise $n(take it as string not variable)

$stid = oci_parse($conn, "SELECT InvoiceNo FROM Orders WHERE OrderNo = $n");

And Pass seconds parameter to function call.

Komal
  • 67
  • 5
0

You miss the second parameter in function and you need to change the query

$stid = oci_parse($conn, 'SELECT InvoiceNo FROM Orders WHERE OrderNo = '.$n);

Use this code for enable error reporting

ini_set('display_errors',1);
error_reporting(-1);
Manibharathi
  • 945
  • 6
  • 18