make login handel script with php and mysql
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given-in-select">mysql_fetch_array() expects parameter 1 to be resource, boolean given in select</a>  </p>
</blockquote>



<p>This is my index.php code:<br/></p>

<pre><code>&lt;?php

session_start();

include ('includes/config.php');
include ('includes/functions.php');

if  (@ $_SESSION['auth']==1 ) {

    redirect("panel",100);

}



?&gt;



&lt;!DOCTYPE HTML&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="content-type" content="text/html" /&gt;
&lt;meta name="Javad Pourmostafa"  /&gt;

&lt;title&gt;رمزنگار Version 1.0&lt;/title&gt;
    &lt;link href="style.css" rel="stylesheet" type="text/css"&gt;
    &lt;/head&gt;

    &lt;body&gt;
    &lt;?php if (!isset($_POST['usname']) &amp;&amp; !isset($_POST['pasw'])) { ?&gt;         



     &lt;div class="head"&gt;
     please enter your username and password:        
     &lt;/div&gt;

     &lt;form action="" method="post" class="form"&gt;

     &lt;p&gt;
     &lt;input name="usname" type="text" class="usp" size="0"&gt;
      &lt;/p&gt;
       &lt;p&gt;
        &lt;input name="pasw" type="password" class="usp" size="0"&gt;
    &lt;/p&gt;
       &lt;p&gt;
     &lt;input name="submit" type="submit" class="submit" value="ورود"&gt;
      &lt;/p&gt;


      &lt;/form&gt;
          &lt;?php } //close if tag ?&gt; 


      &lt;?php 
       if (isset($_POST['usname']) &amp;&amp; isset($_POST['pasw'])){

        $username = mysql_ramznegar($_POST['usname'],$link);
        $password = mysql_ramznegar($_POST['pasw'],$link);

   $query = "SELECT * FROM $tbname WHERE usname='$username' and passw='$password'";
    $admin_result = mysql_query($query,$link);
     $admin_result = mysql_fetch_array($admin_result,MYSQL_ASSOC);


    if($username==$admin_result[usname] &amp;&amp; $password == $admin_result[passw])
     {   

        $_SESSION['auth'] = 1;

            redirect("panel");

               exit;                                

    }
     else{

    echo 'ur username and password is invalid!';
    redirect("index.php");

     }




     }
       ?&gt;
</code></pre>

<p>And this is my functions.php code:<br/>
    

<pre><code>//whole the function of Ramznegar 

//redirect A page 

function redirect($address,$time = 2000){

 print "&lt;script language=\"javascript\" &gt;setTimeout(\"window.location.href    ='$address'\",$time)&lt;/script&gt;" ;            
}

// mysql real escape function to avoid sql injection

function mysql_ramznegar($string,$link){

$string = mysql_real_escape_string($string,$link);

return $string;

 }

    ?&gt;
</code></pre>

<p>And this is my config.php code:<br/>
     

<pre><code> //software information
 $version = 1.0;


 //database information

     $host = "localhost";
     $username = "ramznegar";
     $password = "ramznegar";
     $dbname = "ramznegar";
     $tbname="admin";

  /*-------------------------------------------------------*/

   $link = mysql_connect($host,$username,$password) or die ('خطا در اتصال به بانک اطلاعاتی نرم افزار ');

    $select = mysql_select_db($dbname,$link) or die ('خطا در انتخاب بانک اطلاعاتی نرم افزار');
</code></pre>

<p>And also this is my db :<br/></p>

<pre><code>-- phpMyAdmin SQL Dump
-- version 3.5.2
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Dec 09, 2012 at 09:04 PM
-- Server version: 5.5.25a
-- PHP Version: 5.4.4

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `ramznegar`
--

-- --------------------------------------------------------

--
-- Table structure for table `admin`
--

 CREATE TABLE IF NOT EXISTS `admin` (
 `id` int(10) NOT NULL AUTO_INCREMENT,
 `usname` varchar(20) NOT NULL,
 `passw` varchar(20) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `usname` (`usname`,`passw`)
  ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

  --
   -- Dumping data for table `admin`
  --

  INSERT INTO `admin` (`id`, `usname`, `passw`) VALUES
  (1, 'admin', 'admin');

  /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
  /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
  /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
</code></pre>

<p>First time i wrote it and i got mysql_fetch_error but now i want to edit this script:<br/>
<strong>Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in     C:\xampp\htdocs\ramznegar1\index.php on line 60</strong><br/>
How i should edit my script that is work completely?</p>
