Your queries are likely failing so do some error checking, change your code to the following and post your results.
PHP Code:
<?PHP include("connect.php"); $fnn = $_POST['finoname']; $query = mysql_query("SELECT * FROM files WHERE fileno = '$fnn' ") or die(mysql_error().'<br>query'); $fno = mysql_result($query,0,0); $fname = mysql_result($query,0,1); $floc = mysql_result($query,0,3); $fres = mysql_result($query,0,5); $query2 = mysql_query("SELECT * FROM files WHERE filename = '$fnn' ") or die(mysql_error().'<br>query2'; $fno2 = mysql_result($query2,0,0); $fname2 = mysql_result($query2,0,1); $floc2 = mysql_result($query2,0,3); $fres2 = mysql_result($query2,0,5); $idindb = mysql_query("SELECT * FROM files WHERE filename = '$fnn' OR fileno = '$fnn' ") or die(mysql_error().'<br>idindb query'); $isidindb = mysql_num_rows($idindb);
if ($fnn == ''){ echo "<font color='red'>Please make sure the finoname is correct.</font>"; } else if ($isidindb == 0){ echo "<font color='red'>No record found for that finoname</font>"; }else { echo"<b><font color='red'> $fno$fno2 - $fname$fname2 - $floc$floc2 - $fres$fres2 </font></b>";} ?>
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
Not necessarily failing, the above error indicates its more likely that there are simply no results.
You'll need to make use of mysql_num_rows to check if you can actually move to a record before attempting to retrieve it.
I'm a little curious as to why you have three queries to effectively do the same thing. fileno sounds to me like an integer versus the filename of a string. I wouldn't use the OR statement here, since I could have a filename 1 and a fileno 1 if this assumption is correct. This would assume that filename and fileno do not need to correspond, so you could have unintended results.
If fileno is a number, check it as such first:
PHP Code:
if (isset($_POST['finoname']))
{
$sProvided = $_POST['finoname'];
$sQry = 'SELECT * FROM files';
if (is_numeric($sProvided))
{
$sQry .= ' WHERE fileno = ' . (int)$sProvided;
}
else
{
$sQry .= ' WHERE filename = \'' . mysql_real_escape_string($sProvided) . '\'';
}
Also, since aero replied I realized I biffed something too. With my code rather than having a potential of 2 results with a filename and fileno being the same, I now have only the ability to fetch the fileno instead of the filename, which is actually worse IMO.
So in hinds sight, the OR is probably the best choice here, and use a loop to check the results.
Aero's still right when it comes to some sort of error handling, whether it be a die or something more graceful. You should always check that something does exist off of a resource. Fortunately, resources will return false (or null in some situations) if they fail. So using fopen or mysql_query or whatever can be checked with a simple assignment and if if you would like:
PHP Code:
if ($qry = mysql_query($sQry)) { // good, keep going } else { print 'Oops, something went wrong with site. Please check back later'; }
for example.
Since these are external, you don't want PHP to deal with this itself. This is much like throwing an exception; pass the buck back to the caller to determine how to deal with the failure.