Hello,
I Am having problems with a simple script i wrote to login a username and password from a mysql database.
i get the error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in H:\steadyology\steadyology\account.php on line **21

I ran the script on my localhost where i have php and mysql running. the following is the query i perfomrmed on the datbase table user

<?php 
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
                                                     // always modified
header("Cache-Control: no-store, no-cache, must-revalidate");  // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");                          // HTTP/1.0




include("config.php");


 $user=$_POST["user"]; $user=strtoupper($user);
 $pass=$_POST["pass"];
$query="select password from user where user=$user";

$result=mysql_query("select * from user where user=$user",$db);

if(!($arr=mysql_fetch_array($result))){//rest that username exists

   include("loginerror.htm");
    exit;
 }

 $done=strcmp($arr["password"],$pass);
if(!($done==0)){  // test that password is correct

    include("loginerror.htm");
    exit;

The line number with error is ****if(!($arr=mysql_fetch_array($result)))

the user table has the following fields
user_id (primary key)
user (contains the username)
pass (the password)

Any help will be appreciated.

Thank you
**

1) Echo out your query to the screen. There is an error in it somewhere and that's the best way to find it.

2) Use [ code][/code ] tags when displaying your code. It makes it easier for us to read. :)

The line number with error is if(!($arr=mysql_fetch_array($result)))

Without seeing the actual error output, I would have to assume your error is being caused where you are placing your !($arr ..

Try this usage instead:

$result = mysql_query(.............);
if (mysql_num_rows($result) > 0)
{
    // we do indeed have results.. collect the array
    $arr = mysql_fetch_array($result);
}
else
{
    // do something here if we don't have any rows returned
}

Regards,
Peter

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.