PHP Database Connection Problem

Hi I’m trying to set up a simple php page to view invoices from an access database.

The code I’m actually using connected to a different database and worked perfectly and I’ve just edited it to fit the new database. The only problem is that now when I search for an invoice I know is in the database it always comes back and says that it cannot find it.

I’m sure it’s something stupid to do with where the quotes are but I’ve been staring at it for hours and can’t figure it out. Any help would be appreciated.

Here is the relevant portion of code:

   if (($_REQUEST["searchinvoiceno"])>0)
     {
      $testno=$_REQUEST["searchinvoiceno"];
      $conn=new COM("ADODB.Connection") or exit("Cannot start ADO.");
      $conn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" .realpath("amazonia280.mdb"));
      $rs=new COM("ADODB.Recordset");
      $rs->open("Select Invoice.Cust_No, Date, Cust_Name, Address ".
                "From Invoice Inner Join Customer on Invoice.Cust_No=Customer.Cust_No ".
                "Where Invoice_No = .$testno",$conn);
      if ($rs->EOF)
        echo "Invoice No: $testno not found!";
      else
        {
         $Invoice_No=$testno;
         $Cust_No=$rs->Fields["Cust_No"]->Value;
         $Cust_Name=$rs->Fields["Cust_Name"]->Value;
         $Address=$rs->Fields["Address"]->Value;
         $Date=$rs->Fields["Date"]->Value;
         $rs->close();
         $rs->open("Select Invoice_Item.ISBN, Title, List Price ".
                "From Invoice_Item Inner Join Book on Invoice_Item.ISBN=Book.ISBN ".
                "Where Invoice_No = .$testno",$conn);
         $noitems=0;
         while (!($rs->EOF))
           {
            array_push($itemnoarray,$rs->Fields["ISBN"]->Value);
            array_push($itemnamearray,$rs->Fields["Title"]->Value);
            array_push($pricearray,floatval($rs->Fields["List Price"]->Value));
            array_push($errorarray,0);
            $rs->MoveNext();
            $noitems++;
           }
         $noitems++;
         $total=calcTotal($pricearray,$errorarray,$noitems);
        }

      $rs->close();
      $conn->close();

     }

Hi Kat,

I think you have problem with WHERE clause:
[php]$rs->open("Select Invoice.Cust_No, Date, Cust_Name, Address ".
"From Invoice Inner Join Customer on Invoice.Cust_No=Customer.Cust_No ".
“Where Invoice_No = .$testno”,$conn);
[/php]

It should be,
[php]$rs->open("Select Invoice.Cust_No, Date, Cust_Name, Address ".
"From Invoice Inner Join Customer on Invoice.Cust_No=Customer.Cust_No ".
“Where Invoice_No = $testno”,$conn);
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service