// login.php page

<?php 
    include_once("dba.class.php");
    $msg="";
    if(isset($_POST["btnLogin"])){

        $username=trim(mysql_real_escape_string($_POST["txtUserName"]));
        $password=trim(mysql_real_escape_string($_POST["txtPassword"]));
        if($username != "" or $password != ""){

            $c->LoginAdmin($username,$password);


                    header("location:Admin.php");

            }


        else
            $msg="Invalid User Name or Password";
    }
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login Page</title>
<style type="text/css">
.MSG {
    color: #F00;
}
</style>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
    <tr>
      <td colspan="2"><strong>Login Page</strong></td>
    </tr>
    <tr>
      <td width="95">&nbsp;</td>
      <td width="247" ><?php echo $msg ?></td>
    </tr>
    <tr>
      <td>User Name:</td>
      <td><input type="text" name="txtUserName" id="txtUserName" /></td>
    </tr>
    <tr>
      <td>Password:</td>
      <td><input type="password" name="txtPassword" id="txtPassword" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="btnLogin" id="btnLogin" value="Login" /></td>
    </tr>
  </table>
</form>
</body>
</html>

//db_class page

<?
class dba{
public function __construct()
{
$conn = mysql_connect("localhost","root","root");
mysql_select_db("db",$conn);    
}

function LoginAdmin($username,$password){
           $sql=mysql_query("select * from userinfo where userinfo.username='$username' and password='$password'");
           return $sql;
           $rs=mysql_fetch_array($sql);
       }

}
$c= new dba();          
?>

I got this error"!Fatal error: Class 'dba' not found in C:\wamp\www\Login.php"
what should i do, please?

Member Avatar for diafol

Don't use short tags (<?) - use <?php

the same error still appear :(

Member Avatar for diafol

The code:

class dba{
public function __construct()
{
$conn = mysql_connect("localhost","root","root");
mysql_select_db("db",$conn);    
}
function LoginAdmin($username,$password){
           $sql=mysql_query("select * from userinfo where userinfo.username='$username' and password='$password'");
           return $sql;
           $rs=mysql_fetch_array($sql);
       }
}
$c= new dba();        

does not produce an error when I run it.

I know, i think the problem at the login page, the error is that "the dba class cannot be found at the login page, it seems that the login page cannot recognize it!

Member Avatar for diafol

Well, I can't see the problem, if your $c= new dba(); is in the include file. If your login page wasn't able to pick up the include file at all, then you should get an error message.

**i got this error and it still appear mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\ss\ll.php on line 11.. please help me **

//Login page:

<?php 
    include_once("dba.class.php");
    $msg="";
    if(isset($_POST["btnLogin"])){
        $username=(mysql_real_escape_string($_POST["txtUserName"]));
        $password=(mysql_real_escape_string($_POST["txtPassword"]));
             if($username !="" or $password !=""){
            $rs= $c->LoginAdmin($username, $password);
                if($row=mysql_fetch_array($rs)){
                if($username == $row["username"]){
                header("location:Admin.php");
                }
                else $msg= "Please entwer a vaild username or password";
             }
             }


            else
            $msg="Please enter username and password";
    }
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login Page</title>
<style type="text/css">
.MSG {
    color: #F00;
}
</style>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
    <tr>
      <td colspan="2"><strong>Login Page</strong></td>
    </tr>
    <tr>
      <td width="95">&nbsp;</td>
      <td width="247" ><?php echo $msg ?></td>
    </tr>
    <tr>
      <td>User Name:</td>
      <td><input type="text" name="txtUserName" id="txtUserName" /></td>
    </tr>
    <tr>
      <td>Password:</td>
      <td><input type="password" name="txtPassword" id="txtPassword" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="btnLogin" id="btnLogin" value="Login" /></td>
    </tr>
  </table>
</form>

</body>
</html>


\\The db.class.php page 


<?php

class dba{
public function __construct()
{
$conn = mysql_connect("localhost","","");
mysql_select_db("db",$conn);    
}

  function LoginAdmin($username,$password){
  $sql=mysql_query("select * from userinfo where      username='$username' and password='$password'");
    return $sql;
  }

}

$c= new dba();          
?>
Member Avatar for diafol

It looks as though this is not a valid query: "select * from userinfo where username='$username' and password='$password'"

Run a test inside the function LoginAdmin($username,$password) method
e.g. do a mysql_num_rows().

i think there is not any affected rows!! it prints nothing!!

//login page

             if($username !="" or $password !=""){
            if($c->LoginAdmin($username, $password)>0)
            {$msg="Hi";}
               /* if($row=mysql_fetch_array($rs)){
                if($_SESSION['username'] == $row['username']){
                header("location:Admin.php");
                }
                else $msg= "Please entwer a vaild username or password";
             }*/
             }

//db.class.php


  function LoginAdmin($username,$password){
  $sql=mysql_query("select * from userinfo where username='$username' and password='$password'");
     mysql_query($sql);
     $afectedrows=mysql_affected_rows();
     return $afectedrows;
  }
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.