hi,

although, database is connected and admin table of my database consist of 2 rows of data, I still get 0 value for $numRow=mysql_num_rows($result);
And mysql_fetch_array doesnt fetch values properly

plz can any body help me


thx in advance

<?php
//include_once 'config.php';
 /*
   1. Got the username and password from textboxes on a form
   2. Opened a connection to a database
   3. Validated the username and password
   4. Checked to see if any rows were returned from the database
   5. If rows were returned, set a session variable to 1
   6. If no rows were returned, set a session variable to a blank string
   7. Built up an error message throughout the code
  *
  *
  *
  * if the user has not log in correct username and password redirect to login page
  * otherwise redirect into the admin page.
 */
$user=$_POST['userName'];
$pass=$_POST['password'];
//$user=$userName;
//$pass=$password;
//



if($_SERVER['REQUEST_METHOD']=='POST'){

    //get username and password from admin login.php



    //We then deal with any unwanted HTML (scripting attacks):
    // $uname = htmlspecialchars($user);
    // $pword = htmlspecialchars($pass);
    //connect the database server ans select the database (there is only one database)
    //connectDbases();

    $dbuser="root";
    $dbpswd="ijts";
    $dbserver="localhost";
    $dbname="sahansevena";
    $con=mysql_connect($dbserver,$dbuser,$dbpswd);

    if(!$con){
        die('coudnt connect db connection prob'.mysql_error());
    }else{
        $uname=mysql_real_escape_string($uname);
        $pword=mysql_real_escape_string($pswd);
        
        mysql_select_db($dbname,$con);
        $result="select * from admin where username='$uname' AND password='$pword'";
        //$result=mysql_query($result);
        //$numRow=mysql_num_rows($result);

        //Checked to see if any rows were returned from the database
        // If rows were returned, set a session variable to 1
        $result=mysql_query($result);
        if ($result) {
            $numRow=mysql_num_rows($result);
            $numCol=mysql_num_fields($result);
        }
        else {
            trigger_error(mysql_error(), E_USER_ERROR);
        }


            if($numRow>0){
                //session_start();
                //$_SESSION['login']="1";
                //$_SESSION['user']=$uname;
                //$_SESSION['pswd']=$pword;
                echo "hi now next to header of if part ";
                   echo "hi ".$numCol;
               // header ("Location:adminpage.php");
            while($row= mysql_fetch_array($result,MYSQL_NUM)){
          echo "username".$row[1]."password".$row[2];

           }

    }else{
               // session_start();
                  echo "hi now next to header of else part ";
                  echo "numberof rows ".$numRow."  ";
                echo "hi col ".$numCol;
    //            while($numRow=mysql_fetch_array($result)){
    //                echo " values are".$numRow['username'].$numRow['password']."  ";
    //            }
                // $_SESSION['login'] = "";
               // header ("Location: login.php");

           while($row= mysql_fetch_array($result,MYSQL_NUM)){
           echo "username".$row[1]."password".$row[2];
           }

          }

    }



}else{
    echo 'error message database';

}



?>

I would echo the Select statement and try it in PHPMyAdmin and see if you get any results. If you do, then something is probably going wrong in the connect or select. If you don't, then you need to check the select and see what isn't matching up with the database values.

more demand of PHP just because of Facebook.

i would suggest you to first debug your code....inplace of this

$result="select * from admin where username='$uname' AND password='$pword'";

write this and check whether you are getting any value in mysql_num_rows or not....

$result="select * from admin";

After that tell me what's your output ...Is the problem persist then i will look into it...

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.