Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Warning: mysql_num_rows(): supplied argument is not a valid MySQL resu 1

Status
Not open for further replies.

redzonne

Programmer
Feb 20, 2005
27
US
Hi all,

I am stuck trying to setup an Authentication with Session Control form

I keep getting the WARNING ERROR:Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/realest1/public_html/sellhome2.php on line 19

realest1_proppost is the database
and customers is the table

Could someone take a look at the code and tell me what I may be doing wrong?

<?

session_start();

if(!isset($HTTP_POST_VARS['login']) && !isset($HTTP_POST_VARS['password']))
{

$login = $HTTP_POST_VARS['login'];
$password = $HTTP_POST_VARS['password'];

$dbconnect = mysql_connect( 'localhost', 'MYDATABSE', 'MYDBPASSWORD' );
mysql_select_db ( 'realest1_proppost', $dbconnect);

$query = 'select (*) from customers '
."where login='$login' "
." and password=password('$password') ";

$result = mysql_query($query, $dbconnect);
if (mysql_num_rows($result) >0 )
{
$HTTP_SESSION_VARS['valid_user'] = $login;
}
}
?>
<?php
if( $login == 'login' && crypt($password, 'xx') == 'xxhaveaGreatDay' )
{
//OK passwords match
}
?>
<?php

$pictures = array( '/main_img/indexsplash.jpg' , '/main_img/indexsplash1.jpg' , '/main_img/indexsplash2.jpg' , '/main_img/indexsplash3.jpg' );

srand ((float)microtime()*1000000);
shuffle ($pictures);

?>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title>Welcome to *Real Estate Net Find* - List Your Home for Sale</title>
<META name="keywords" content="real estate,real-estate,home search,find a home,find a realtor,realtor, mortgage, homes for sale,home buying">
<META name="description" content="RealEstatenetfdind.com is premier provider of Califonia home listings, new West Coast homes for sale, finding a reputable REALTOR">
<link href="css/css_realestate.css" type="text/css" rel="stylesheet">
</head>

<body bgColor=#ffffff leftMargin=0 topMargin=0 MARGINHEIGHT="0" MARGINWIDTH="0">
<? include("includes/120x600bnr_ary.inc") ?><? include("includes/topnav03.php") ?>
<table border="0" cellpadding="0" cellspacing="0" width="754">
<tr height="6">
<td colspan="5" height="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
</tr>
<tr>
<td width="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
<td width="179" valign="top"><? include("includes/leftnav03.php") ?>
<table border="0" cellpadding="0" cellspacing="0" width="179" height="2">
<tr>
<td><img src="/main_img/2px_spacer.gif" width="2" height="2" border="0"></td>
</tr>
</table>
<? include("includes/leftnv_whatsnewincl.php") ?></td>
<td width="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
<td bgcolor="#e1e7ee" valign="top">
<table border="0" cellpadding="0" cellspacing="0" width="557" bgcolor="#6d79ad" height="19">
<tr>
<td width="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
<td><span class=pwhite>LIST&nbsp;YOUR&nbsp;HOME FOR&nbsp;SALE</span></td>
<td width="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="557">
<tr>
<td colspan="3"><img src="/main_img/home_plateau.jpg" width="557" height="42" border="0"></td>
</tr>
<tr>
<td colspan="3"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
</tr>
<tr>
<td width="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
<td width="545"><span class=psparkblu12><b>LIMITED TIME OFFER</b>: Since we are a brand new home search site entering the business, we wish to intially fill our database with many Southern California homes for sale to get our service started. All new home postings are absolutely free until we decide to switch to charging per listing. Real estate agents and private sellers take advantage of the FREE opportunity to list your property, today.</span><br>
<br>
<span class=psparkblu12><b>ABSOLUTELY&nbsp;NO OBLIGATION OR HIDDEN FEES!</b><br>
</span><br>
<span class=psparkblu12>Please login below, if your already have an account with us.</span></td>
<td width="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
</tr>
<tr>
<td colspan="3"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
</tr>
<tr>
<td colspan="3">
<HR WIDTH="545" SIZE=1 NOSHADE>
</td>
</tr>
<tr>
<td></td>
<td width="545" align="center">
<?
if (isset($HTTP_SESSION_VARS['valid_user']))
{
echo '<span class=psparkred12></br></span>';
echo '<span class=psparkred12>You are logged in as: '.$HTTP_SESSION_VARS['valid_user'].' </br></span>';
}
else
{
if (isset($userid))
{
echo '<span class=psparkred12></br></span>';
echo '<span class=psparkred12>* Invalid UserName and/or password. Please try again.</br></span>';
}
else
{
echo '<span class=psparkblu12></span>';
}
echo '<FORM ACTION="sellhome2.php" METHOD="POST">';
echo '<table border="0" cellpadding="0" cellspacing="0">';
echo '<tr>';
echo '<td><span class=psparkblu12>Login</span></td>';
echo '<td width="10" valign="middle"><img src="/main_img/10px_spacer.gif" width="10" height="10" border="0"></td>';
echo '<td><input type="text" name="login" size="12" tabindex="6"></td>';
echo '<td width="40"><img src="/main_img/10x40px_spacer.gif" width="40" height="10" border="0"></td>';
echo '<td><span class=psparkblu12>Password</span></td>';
echo '<td width="10" align="center"><img src="/main_img/10px_spacer.gif" width="10" height="10" border="0"></td>';
echo '<td><input type="text" name="password" size="12" tabindex="6"></td>';
echo '<td width="30" align="center"><img src="/main_img/10x30px_spacer.gif" width="30" height="10" border="0"></td>';
echo '<td><input name="Submit" type="submit" value="LOGIN"></td>';
echo '</tr>';
echo '</table>';
}
?>
<td></td>
</tr>
<tr height="6">
<td colspan="3" height="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
</tr>
<tr>
<td colspan="3">
<HR WIDTH="545" SIZE=1 NOSHADE>
</td>
</tr>
</table>
</td>
<td width="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
</tr>
<tr height="6">
<td colspan="5" height="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
</tr>
</table>
<? include("includes/tipoftheday.inc") ?>
<? include("includes/botnav03.php") ?>
</body>
</html>
 
It seems as if you are a receiving an error from mySQL instead of having a valid return set.

I looked at your query and the only thing that stands out is this line in the query:

and password=password('$password') ";

I'm not a SQL guru, but shouldn't the line read:

and password='$password' ";
 
Ok I tried change the line in the query from

and password=password('$password') ";
to
Find A Forum Search Posts (Keyword) Thread Number Threads by Handle Search FAQs (Keyword) Search Links (Keyword) Find An Expert Advanced Search

Home > Forums > Programmers > Graphics & Web Tools > PHP Forum
Warning: mysql_num_rows(): supplied argument is not a valid MySQL resu
thread434-1009586
Forum Search FAQs Links

Read
New Posts Reply To
This Thread
E-mail It
Print It Next
Thread

redzonne (Programmer) Feb 20, 2005
Hi all,

I am stuck trying to setup an Authentication with Session Control form

I keep getting the WARNING ERROR:Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/realest1/public_html/sellhome2.php on line 19

realest1_proppost is the database
and customers is the table

Could someone take a look at the code and tell me what I may be doing wrong?

<?

session_start();

if(!isset($HTTP_POST_VARS['login']) && !isset($HTTP_POST_VARS['password']))
{

$login = $HTTP_POST_VARS['login'];
$password = $HTTP_POST_VARS['password'];

$dbconnect = mysql_connect( 'localhost', 'MYDATABSE', 'MYDBPASSWORD' );
mysql_select_db ( 'realest1_proppost', $dbconnect);

$query = 'select (*) from customers '
."where login='$login' "
." and password=password('$password') ";

$result = mysql_query($query, $dbconnect);
if (mysql_num_rows($result) >0 )
{
$HTTP_SESSION_VARS['valid_user'] = $login;
}
}
?>
<?php
if( $login == 'login' && crypt($password, 'xx') == 'xxhaveaGreatDay' )
{
//OK passwords match
}
?>
<?php

$pictures = array( '/main_img/indexsplash.jpg' , '/main_img/indexsplash1.jpg' , '/main_img/indexsplash2.jpg' , '/main_img/indexsplash3.jpg' );

srand ((float)microtime()*1000000);
shuffle ($pictures);

?>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title>Welcome to *Real Estate Net Find* - List Your Home for Sale</title>
<META name="keywords" content="real estate,real-estate,home search,find a home,find a realtor,realtor, mortgage, homes for sale,home buying">
<META name="description" content="RealEstatenetfdind.com is premier provider of Califonia home listings, new West Coast homes for sale, finding a reputable REALTOR">
<link href="css/css_realestate.css" type="text/css" rel="stylesheet">
</head>

<body bgColor=#ffffff leftMargin=0 topMargin=0 MARGINHEIGHT="0" MARGINWIDTH="0">
<? include("includes/120x600bnr_ary.inc") ?><? include("includes/topnav03.php") ?>
<table border="0" cellpadding="0" cellspacing="0" width="754">
<tr height="6">
<td colspan="5" height="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
</tr>
<tr>
<td width="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
<td width="179" valign="top"><? include("includes/leftnav03.php") ?>
<table border="0" cellpadding="0" cellspacing="0" width="179" height="2">
<tr>
<td><img src="/main_img/2px_spacer.gif" width="2" height="2" border="0"></td>
</tr>
</table>
<? include("includes/leftnv_whatsnewincl.php") ?></td>
<td width="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
<td bgcolor="#e1e7ee" valign="top">
<table border="0" cellpadding="0" cellspacing="0" width="557" bgcolor="#6d79ad" height="19">
<tr>
<td width="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
<td><span class=pwhite>LIST&nbsp;YOUR&nbsp;HOME FOR&nbsp;SALE</span></td>
<td width="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="557">
<tr>
<td colspan="3"><img src="/main_img/home_plateau.jpg" width="557" height="42" border="0"></td>
</tr>
<tr>
<td colspan="3"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
</tr>
<tr>
<td width="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
<td width="545"><span class=psparkblu12><b>LIMITED TIME OFFER</b>: Since we are a brand new home search site entering the business, we wish to intially fill our database with many Southern California homes for sale to get our service started. All new home postings are absolutely free until we decide to switch to charging per listing. Real estate agents and private sellers take advantage of the FREE opportunity to list your property, today.</span><br>
<br>
<span class=psparkblu12><b>ABSOLUTELY&nbsp;NO OBLIGATION OR HIDDEN FEES!</b><br>
</span><br>
<span class=psparkblu12>Please login below, if your already have an account with us.</span></td>
<td width="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
</tr>
<tr>
<td colspan="3"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
</tr>
<tr>
<td colspan="3">
<HR WIDTH="545" SIZE=1 NOSHADE>
</td>
</tr>
<tr>
<td></td>
<td width="545" align="center">
<?
if (isset($HTTP_SESSION_VARS['valid_user']))
{
echo '<span class=psparkred12></br></span>';
echo '<span class=psparkred12>You are logged in as: '.$HTTP_SESSION_VARS['valid_user'].' </br></span>';
}
else
{
if (isset($userid))
{
echo '<span class=psparkred12></br></span>';
echo '<span class=psparkred12>* Invalid UserName and/or password. Please try again.</br></span>';
}
else
{
echo '<span class=psparkblu12></span>';
}
echo '<FORM ACTION="sellhome2.php" METHOD="POST">';
echo '<table border="0" cellpadding="0" cellspacing="0">';
echo '<tr>';
echo '<td><span class=psparkblu12>Login</span></td>';
echo '<td width="10" valign="middle"><img src="/main_img/10px_spacer.gif" width="10" height="10" border="0"></td>';
echo '<td><input type="text" name="login" size="12" tabindex="6"></td>';
echo '<td width="40"><img src="/main_img/10x40px_spacer.gif" width="40" height="10" border="0"></td>';
echo '<td><span class=psparkblu12>Password</span></td>';
echo '<td width="10" align="center"><img src="/main_img/10px_spacer.gif" width="10" height="10" border="0"></td>';
echo '<td><input type="text" name="password" size="12" tabindex="6"></td>';
echo '<td width="30" align="center"><img src="/main_img/10x30px_spacer.gif" width="30" height="10" border="0"></td>';
echo '<td><input name="Submit" type="submit" value="LOGIN"></td>';
echo '</tr>';
echo '</table>';
}
?>
<td></td>
</tr>
<tr height="6">
<td colspan="3" height="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
</tr>
<tr>
<td colspan="3">
<HR WIDTH="545" SIZE=1 NOSHADE>
</td>
</tr>
</table>
</td>
<td width="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
</tr>
<tr height="6">
<td colspan="5" height="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
</tr>
</table>
<? include("includes/tipoftheday.inc") ?>
<? include("includes/botnav03.php") ?>
</body>
</html>


Inappropriate post?
If so, Red Flag it!


Check out the FAQ
area for this forum!




Start Your Own Tek-Tips Group! Click Here!
redzonne (Programmer) Feb 20, 2005
here is the link :

Inappropriate post?
If so, Red Flag it!


Check out the FAQ
area for this forum!



Itshim (Programmer) Feb 20, 2005
It seems as if you are a receiving an error from mySQL instead of having a valid return set.

I looked at your query and the only thing that stands out is this line in the query:

and password=password('$password') ";

I'm not a SQL guru, but shouldn't the line read:

and password='$password' ";

There warning is still there. Could it be something else?

<?

session_start();

if(!isset($HTTP_POST_VARS['login']) && !isset($HTTP_POST_VARS['password']))
{

$login = $HTTP_POST_VARS['login'];
$password = $HTTP_POST_VARS['password'];

$dbconnect = mysql_connect( 'localhost', 'realest1_user', 'netall' );
mysql_select_db ( 'realest1_proppost', $dbconnect);

$query = 'select (*) from customers '
."where login='$login' "
." and password='$password' ";

$result = mysql_query($query, $dbconnect);
if (mysql_num_rows($result) >0 )
{
$HTTP_SESSION_VARS['valid_user'] = $login;
}
}
?>
<?php
if( $login == 'login' && crypt($password, 'xx') == 'xxhaveaGreatDay' )
{
//OK passwords match
}
?>
<?php

$pictures = array( '/main_img/indexsplash.jpg' , '/main_img/indexsplash1.jpg' , '/main_img/indexsplash2.jpg' , '/main_img/indexsplash3.jpg' );

srand ((float)microtime()*1000000);
shuffle ($pictures);

?>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title>Welcome to *Real Estate Net Find* - List Your Home for Sale</title>
<META name="keywords" content="real estate,real-estate,home search,find a home,find a realtor,realtor, mortgage, homes for sale,home buying">
<META name="description" content="RealEstatenetfdind.com is premier provider of Califonia home listings, new West Coast homes for sale, finding a reputable REALTOR">
<link href="css/css_realestate.css" type="text/css" rel="stylesheet">
</head>

<body bgColor=#ffffff leftMargin=0 topMargin=0 MARGINHEIGHT="0" MARGINWIDTH="0">
<? include("includes/120x600bnr_ary.inc") ?><? include("includes/topnav03.php") ?>
<table border="0" cellpadding="0" cellspacing="0" width="754">
<tr height="6">
<td colspan="5" height="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
</tr>
<tr>
<td width="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
<td width="179" valign="top"><? include("includes/leftnav03.php") ?>
<table border="0" cellpadding="0" cellspacing="0" width="179" height="2">
<tr>
<td><img src="/main_img/2px_spacer.gif" width="2" height="2" border="0"></td>
</tr>
</table>
<? include("includes/leftnv_whatsnewincl.php") ?></td>
<td width="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
<td bgcolor="#e1e7ee" valign="top">
<table border="0" cellpadding="0" cellspacing="0" width="557" bgcolor="#6d79ad" height="19">
<tr>
<td width="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
<td><span class=pwhite>LIST&nbsp;YOUR&nbsp;HOME FOR&nbsp;SALE</span></td>
<td width="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="557">
<tr>
<td colspan="3"><img src="/main_img/home_plateau.jpg" width="557" height="42" border="0"></td>
</tr>
<tr>
<td colspan="3"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
</tr>
<tr>
<td width="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
<td width="545"><span class=psparkblu12><b>LIMITED TIME OFFER</b>: Since we are a brand new home search site entering the business, we wish to intially fill our database with many Southern California homes for sale to get our service started. All new home postings are absolutely free until we decide to switch to charging per listing. Real estate agents and private sellers take advantage of the FREE opportunity to list your property, today.</span><br>
<br>
<span class=psparkblu12><b>ABSOLUTELY&nbsp;NO OBLIGATION OR HIDDEN FEES!</b><br>
</span><br>
<span class=psparkblu12>Please login below, if your already have an account with us.</span></td>
<td width="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
</tr>
<tr>
<td colspan="3"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
</tr>
<tr>
<td colspan="3">
<HR WIDTH="545" SIZE=1 NOSHADE>
</td>
</tr>
<tr>
<td></td>
<td width="545" align="center">
<?
if (isset($HTTP_SESSION_VARS['valid_user']))
{
echo '<span class=psparkred12></br></span>';
echo '<span class=psparkred12>You are logged in as: '.$HTTP_SESSION_VARS['valid_user'].' </br></span>';
}
else
{
if (isset($userid))
{
echo '<span class=psparkred12></br></span>';
echo '<span class=psparkred12>* Invalid UserName and/or password. Please try again.</br></span>';
}
else
{
echo '<span class=psparkblu12></span>';
}
echo '<FORM ACTION="sellhome2.php" METHOD="POST">';
echo '<table border="0" cellpadding="0" cellspacing="0">';
echo '<tr>';
echo '<td><span class=psparkblu12>Login</span></td>';
echo '<td width="10" valign="middle"><img src="/main_img/10px_spacer.gif" width="10" height="10" border="0"></td>';
echo '<td><input type="text" name="login" size="12" tabindex="6"></td>';
echo '<td width="40"><img src="/main_img/10x40px_spacer.gif" width="40" height="10" border="0"></td>';
echo '<td><span class=psparkblu12>Password</span></td>';
echo '<td width="10" align="center"><img src="/main_img/10px_spacer.gif" width="10" height="10" border="0"></td>';
echo '<td><input type="text" name="password" size="12" tabindex="6"></td>';
echo '<td width="30" align="center"><img src="/main_img/10x30px_spacer.gif" width="30" height="10" border="0"></td>';
echo '<td><input name="Submit" type="submit" value="LOGIN"></td>';
echo '</tr>';
echo '</table>';
}
?>
<td></td>
</tr>
<tr height="6">
<td colspan="3" height="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
</tr>
<tr>
<td colspan="3">
<HR WIDTH="545" SIZE=1 NOSHADE>
</td>
</tr>
</table>
</td>
<td width="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
</tr>
<tr height="6">
<td colspan="5" height="6"><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td>
</tr>
</table>
<? include("includes/tipoftheday.inc") ?>
<? include("includes/botnav03.php") ?>
</body>
</html>
 
I don't believe you should have "... and `password`=password('$password')" as it should be "... and `password`='$password'" as was mentioned before. You getting the error that mysql_num_rows() invalid arguement means that your query failed. To correct for this error in the future you should add another if statement that goes:
Code:
if (!$query)
{
//Query has errored.
} else {
//Query OK.
}
 
Hi Try this query below exactly as it is should work now

$query = 'SELECT * FROM customers'
.'where login="' . $login . '"'
.'and password="' . $password . '"';

illogicalcode
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top