Jump to content

ms access 2007 and php


jeet

Recommended Posts

<?php
if(isset($_GET['b_no'])){
$bno=$_GET['b_no'];

include("connect.php");
$query19="select * from billing where `b_no`=$bno";

$rs19=$conn->execute($query19);

if($rs19){
$itm=explode(',',$rs19['item']);
$qty=explode(',',$rs19['qty']);
$r=count($itm);


for($i=0;$i<=$r;$i++) {
if(isset($itm[$i]) && isset($qty[$i])) {
echo "item".$itm[$i];
echo "qty".$qty[$i];
echo "<br>";
}
}

}
else {
echo "no records found";
}
}

else {
echo "enter bill no";
}
?>



this is my code for fetching records by passing a bill number . it runs fine if i pass a bill number which is present in the table but if i pass a bill number ($bno ) which is not present in the billing table then also the control goes to if statement and executes explode function and all.
basically my question is how to validate  hte select query .

Link to comment
Share on other sites

Without knowing what $conn->execute does, we can't say much about how your code is going to process. Based on your description it sounds as though it will return a true-ish value regardless of if actual rows are found or not. If that is the case you will need to find another way of determining whether a row was actually found.

 

If you provide details on what $conn->execute does, by providing it's source for example, perhaps we can further help you figure out how to properly detect an empty result set.

 

Also, for future reference, you need to enclose your code within


tags when you post it. Failure to do so will greatly decrease your chances of getting help.

Link to comment
Share on other sites

 

<?php

$conn = new COM ("ADODB.Connection")
  or die("Cannot start ADO");

$connStr = "PROVIDER=Microsoft.Ace.OLEDB.12.0;Data Source= C:\Arihant_billing\db\arihant_thali.accdb";

  $conn->open($connStr);
  ?>



this code is in connect.php Edited by jeet
Link to comment
Share on other sites

<?php
if(isset($_GET['b_no'])){
$bno=$_GET['b_no'];

include("connect.php");
$query19="select * from billing where `b_no`=$bno";

$rs19=$conn->execute($query19);

if($rs19){
$itm=explode(',',$rs19['item']);
$qty=explode(',',$rs19['qty']);
$r=count($itm); 


for($i=0;$i<=$r;$i++) { 
if(isset($itm[$i]) && isset($qty[$i])) {
echo "item".$itm[$i];
echo "qty".$qty[$i];
echo "<br>"; 
}
}

}
else {
echo "no records found";
}
}

else {
echo "enter bill no";
}
?> 

 

this is my code for fetching records by passing a bill number . it runs fine if i pass a bill number which is present in the table but if i pass a bill number ($bno ) which is not present in the billing table then also the control goes to if statement and executes explode function and all.

basically my question is how to validate  hte select query .

Link to comment
Share on other sites

with this line:

if($rs19){ .....

you are testing if the Execute() method was indeed able to execute correctly the SQL sentence and return a valid recordset, however, as kicken pointed out before, that doesn't guarantee that the select effectively returned rows or not, and you are not checking/validating that condition.

 

What you probably want to do is more or less this (only relevant code shown):

$query19="select * from billing where `b_no`=$bno";
$rs19=$conn->execute($query19);
if (!$rs19) {                           // validate that a valid recordset has been generated without errors or not
         print $conn->ErrorMsg();
         exit(); // maybe you want to stop the script in case of error
} else {
  // We have a valid record set (could be empty), one option is validate that it is not empty, other is loop the recordset WHILE it hasn't reached the EOF
   if ($rs19->EOF) {
       echo "No Records found... (or recordset exhausted)";
       // do something else or exit
   } else {
     // Green light... rest of your code
   }
}

[EDIT]: this link could help : http://phplens.com/lens/adodb/docs-adodb.htm

Edited by mikosiko
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.