Hello all,

First and foremost I would like to thank anyone who will end up contributing to this thread. I'm relatively new to PHP/MySQL and did a site migration for a client to a different server. The website was working perfectly fine before, however now I am getting these errors. I will post the php codes below. Any help is appreciated!


Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /hermes/web11/b1630/moo.thchealthorg/controlpanel/includes/connection.php on line 29

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /hermes/web11/b1630/moo.thchealthorg/login.php on line 45

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /hermes/web11/b1630/moo.thchealthorg/login.php on line 64

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /hermes/web11/b1630/moo.thchealthorg/login.php on line 86

connection.php

<?php

	$host = "********";
    $dbusername = "********";
	$dbpassword = "*********";	
	$dbname = "********";
		
function db_connect()
{
	error_reporting(E_ALL ^ E_NOTICE); 
	global $host,$dbusername,$dbpassword,$dbname;
	if(!($link_id=mysql_pconnect($host,$dbusername,$dbpassword)))
	{
		echo("Error connecting to Host.");
		exit();
	}
	if(!mysql_select_db($dbname,$link_id))
	{
		echo("Error in selecting the Database.");
	}
	return $link_id;
}

//getting company name
$linkid=db_connect();

$sql = "select * from settings order by SId desc";
$res = mysql_query($sql);
$numrows = mysql_num_rows($res);
if($numrowscon>0)
{ 
	$objcon= mysql_fetch_object($res);
	
	$_SESSION['company']=$objcon->Company;
}
?>

login.php

<?php
ob_start();
session_start();
include("controlpanel/includes/connection.php");
include("includes/functions.php");

/*if($_SERVER['HTTPS']!="on")
{
	header('location:https://'.$_SERVER['SERVER_NAME'].'/'.$_SERVER['PHP_SELF']); 
	exit;
}*/

if ($_REQUEST["mode"]=="logout") //if logout
{
	$_SESSION['_name']="";
	$_SESSION['_email']="";
	$_SESSION['_did']="";
	$_SESSION['_pid']="";
	$_SESSION['_aid']="";
	$_SESSION['_check']="<font color='green'>Logout successful.</font>";
}

if($_SESSION['_pid']!="")
{
	header("location:patient_login.php");
	die();
}
elseif($_SESSION['_did']!="")
{
	header("location:doctor_login.php");
	die();
}
elseif($_SESSION['_aid']!="")
{
	header("location:agent_login.php");
	die();
}

if ($_REQUEST["mode"]=="login")
{
	$valid="no";
	
	$sql = "select * from agent where (Email='".$_REQUEST['Email']."' or RegNo='".$_REQUEST['Email']."') and Password='".$_REQUEST['Password']."' and Status!='Inactive' and Status!='Pending'";
	$res = mysql_query($sql);
	$numrows = mysql_num_rows($res);
	
	if($numrows>0)
	{
		$obj= mysql_fetch_object($res);
		
		$valid="yes";
		$_SESSION['_aid']= $obj->AId;
		$_SESSION['_pid']="";
		$_SESSION['_did']="";
		$_SESSION['_name']= $obj->CompanyName;
		$_SESSION['_email']=$obj->Email;
		
		header("location:agent_login.php");
	}
	else
	{
		$sql = "select * from doctor where (Email='".$_REQUEST['Email']."' or RegNo='".$_REQUEST['Email']."') and Password='".$_REQUEST['Password']."' and Status!='Inactive' and Status!='Pending'";
		$res = mysql_query($sql);
		$numrows = mysql_num_rows($res);
		
		if($numrows>0)
		{
			$obj= mysql_fetch_object($res);
			
			$valid="yes";
			$_SESSION['_did']= $obj->DId;
			$_SESSION['_pid']="";
			$_SESSION['_aid']="";
			$_SESSION['_name']= $obj->FirstName;
			$_SESSION['_email']=$obj->Email;
			
			if($obj->SignatureUpload=="")
				header("location:doctor_edit_profile.php");
			else
				header("location:doctor_appointment.php");
		}
		else
		{
			$sql = "select * from patient where (Email='".$_REQUEST['Email']."' or RegNo='".$_REQUEST['Email']."') and Password='".$_REQUEST['Password']."' and Status!='Inactive' and Status!='Pending'";
			$res = mysql_query($sql);
			$numrows = mysql_num_rows($res);
			
			if($numrows>0)
			{
				$obj= mysql_fetch_object($res);
				
				$valid="yes";
				$_SESSION['_pid']= $obj->PId;
				$_SESSION['_did']="";
				$_SESSION['_aid']="";
				$_SESSION['_name']= $obj->FirstName;
				$_SESSION['_email']=$obj->Email;
				
				if($obj->Status=="Certified")
					header("location:patient_certificate.php");
				else
					header("location:patient_login.php");
			}
		}
	}
	
	if($valid=="no")
	{
		$_SESSION['_check']="<font style='color:#ff0000'>Invalid Username / Password.</font>";			
		$_SESSION['_name']= "";
		$_SESSION['_email']="";
		$_SESSION['_did']="";
		$_SESSION['_pid']="";
		$_SESSION['_aid']="";
	}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>TeleHealth Consultants</title>
<link href="includes/style.css" type="text/css" rel="stylesheet">
<? echo fnScript(); ?>
<script type="text/javascript">
function fnValidate()
{
	if(isNull(document.thisForm.Email,"Registration No. / Email")){ return false; }
	if(isNull(document.thisForm.Password,"Password")) { return false; }
}
</script>
</head>
<body>
<table width="890" border="0" cellpadding="0" cellspacing="0" align="center">
	<? echo fnHeader(); ?>
	<tr>
		<td colspan="2" class="pad_top15"><img src="images/top_curve.png" width="890" height="58" border="0"></td>
	</tr>
	<tr>
		<td width="278" valign="top" class="learnmore_form_area">
			<table width="278" border="0" cellpadding="0" cellspacing="0">
				<? echo fnLeft(); ?>
			</table>
		</td>
		<td valign="top" bgcolor="#FFFFFF" width="612">
			<table width="612" border="0" cellpadding="0" cellspacing="0">
				<? echo fnHeaderMenu("Register"); ?>
				<tr>
					<td height="14" bgcolor="#259308"></td>
				</tr>
				<tr>
					<td bgcolor="#FFFFFF" valign="top">
						<div class="content_box"><h1>Login</h1>
							<img src="images/line.jpg" width="575" height="6" border="0"><br>
							
							<b>Please login to enjoy our services.</b><br>
							<form name="thisForm" action="login.php?mode=login" method="post" onSubmit="return fnValidate()">
								<?
								if($_SESSION['_check']!="") {
									echo $_SESSION['_check'];
									$_SESSION['_check']="";
								}
								?>
								<table width="400" border="0" cellpadding="4" cellspacing="0" class="about_content">
									<tr valign="top">
										<td>Registration No. / Email</td>
										<td align="right"><input type="text" name="Email" class="txtarea"> </td>
									</tr>
									<tr valign="top">
										<td>Password</td>
										<td align="right"><input type="password" name="Password" class="txtarea"> </td>
									</tr>
									<tr>
										<td>&nbsp;</td>
										<td>
											<input type="submit" value="Login" class="submit_form2"/>
										</td>
									</tr>
									<tr><td colspan="2"></td></tr>
									<tr>
										<td><a href="agent_register.php"><b>Register Now!</b></a></td>
										<td align="right"><a href="agent_forgot.php"><b>Forgot Password?</b></a></td>
									</tr>
								</table>
							</form>
						</div>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td><img src="images/btn_left.png" width="278" height="72"></td>
		<td>
			<? echo fnFooter(); ?>
		</td>
	</tr>
</table>
<? echo fnGoogle(); ?>
</body>
</html>

You may want to read the sticky thread first.

I did, however I still could not figure out the solution.

It appears to me that you are not actually connecting to your database - you have a function to connect and you load that function into a variable but that is all. Take you database connection out of the function (i.e. to just let it happen when you load the page) and see if that helps (on your connection.php page first).

If that does resolve your problem and you want to keep the connection in a function you need to put your $linkid variable in your query to connect to the database and run your select query (I don't use this method so can't tell you how to format it).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.