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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

password protection web page problem#3

Status
Not open for further replies.

rosesau

Programmer
May 24, 2001
9
AU
Hi,

i think i have nearly worked this out i have just two problems left. these are the problems
Warning: Supplied argument is not a valid MySQL result resource in C:\Inetpub\ on line 18

Warning: Cannot add header information - headers already sent by (output started at C:\Inetpub\ in C:\Inetpub\ on line 31

it has something to do with the folloing code

$MyConn=mysql_connect("ROSES","admin","little");
mysql_select_db("tbllogin.db",$MyConn);

$SQL="Select UserName, Password From tblLogin
_,Where UserName=$UserName,Password=$Password";

$RS_query=mysql_query(($SQL),$MyConn);
$RS=mysql_fetch_array($RS_query);

if (!($RS==0))
{

$allow_session=true;

header("Location: exit;
}
else
{

header("Location:
mysql_close($MyConn);
$RS=null;

$MyConn=null;
exit;
}

my messages are also not short :p
does anyone have any ideas as to where i have gone wrong this time :p

one other question does mysql support accessing a paradox database?

thanks

rose
 
It's the following line that's giving you problems:
Code:
$SQL="Select UserName, Password From tblLogin 
_,Where UserName=$UserName,Password=$Password";
You will receive the "not a valid MySQL resource" message whenever you have an error in your SQL statement. In this case, the error is in the Username=...etc. area

The proper syntax should be:
Code:
$SQL="SELECT UserName, Password FROM tblLogin WHERE UserName='$UserName' AND Password='$Password'";
And that should fix your problem. But let me make one more suggestion. Since you're not using the results UserName and Password in your script, just checking to see if they exist on the same row in your database, try to change your SELECT column to some constant -- 1, for instance. Then your statement becomes:
Code:
$SQL="SELECT 1 FROM tblLogin WHERE UserName='$UserName' AND Password='$Password'";
You can then take out:
$RS=mysql_fetch_array($RS_query);
and replace the
Code:
if (!($RS==0))
with
Code:
if(mysql_num_rows($RS_query))

That way, your database server isn't retrieving unnecessary data, and thus, you don't use as much of your system resources.

Hope this helps,

brendanc@icehouse.net
 
Also, a HEADER instruction should be the very first thing on a page. If you do anything else b4 hand, like HTMl, then you get A Headers already sent error. Dean Owen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top