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
https://forums.phpfreaks.com/topic/281491-ms-access-2007-and-php/
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.

<?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 .

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.