hi..
i'll ask some question regarding my system login part..
This is my databasae connection..

<?
   
      include("constants.php");
 
       
   
      class MySQLDB
   
      {

      var $connection; //The MySQL database connection
   
      function MySQLDB(){
 
      /* Make connection to database */
 
      $this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
  
      mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());

      function confirmUserPass($username, $password){

      /* Add slashes if necessary (for query) */
 
      if(!get_magic_quotes_gpc()) {
  
      $username = addslashes($username);

      }
  
      /* Verify that user is in database */
  
      $q = "SELECT password FROM ".userpass." WHERE username = '$username'";

      $result = mysql_query($q, $this->connection);

      if(!$result || (mysql_numrows($result) < 1)){
 
      return 1; //Indicates username failure
     }
 
       

      /* Validate that password is correct */

      if($password == $dbarray['password']){

      return 0; //Success! Username and password confirmed

      }
  
      else{
 
      return 2; //Indicates password failure
  
      }

      }
 
      $q = "SELECT id FROM ".userpass." WHERE username = '$username'";

      $result = mysql_query($q, $this->connection);
  
      if(!$result || (mysql_numrows($result) < 1)){
 
      return 1; //Indicates username failure

      }
 
       
 
      ?>

my system does not run well.the username as well as the password is saved on it's database.my database name is 'records' and it's table name is 'userpass'...i can't log..what do you think the problem with my code?
all i want is insert username and password from the textbox in the login menu then validate from it's database. when i click the login button,it will proceed to my main page.

Recommended Answers

All 6 Replies

Member Avatar for nileshgr

First change your coding style. You are coding in PHP 4 style which is now obsolote. PHP 4 has been withdrawn.

Next the place where you have written userpass should be inside quotes unless its defined in constants.php.

Then you've not ended the constructor function (syntax error).

And where are you putting the value of password in $dbarray ? There's no fetch statement ?

try to use mysql_num_rows instead mysql_numrows

here:

if(!$result || (mysql_num_rows($result) < 1)){
 
      return 1; //Indicates username failure
     }

and here:

if(!$result || (mysql_num_rows($result) < 1)){
 
      return 1; //Indicates username failure

      }

and try to fetch the result to fill $dbarray like this:

$result = mysql_query($q, $this->connection);
$dbarray = mysql_fetch_array($result);

First change your coding style. You are coding in PHP 4 style which is now obsolote. PHP 4 has been withdrawn.

Next the place where you have written userpass should be inside quotes unless its defined in constants.php.

Then you've not ended the constructor function (syntax error).

And where are you putting the value of password in $dbarray ? There's no fetch statement ?

ok..i'll try to change my code..then after,if it does not work,i'll informyou..tnx

try to use mysql_num_rows instead mysql_numrows

here:

if(!$result || (mysql_num_rows($result) < 1)){
 
      return 1; //Indicates username failure
     }

and here:

if(!$result || (mysql_num_rows($result) < 1)){
 
      return 1; //Indicates username failure

      }

and try to fetch the result to fill $dbarray like this:

$result = mysql_query($q, $this->connection);
$dbarray = mysql_fetch_array($result);

This is the codes i used in my login based on it's database.It works well.But i forgot something..I want to post the current user when he/she login.When they enter their student # as well as their birthday in the login menu,then when they click the button,the information of the current user must display or post on the left side of my webpage.Student #,name,course,year,abd department that saved on the database should appear in my webpage.How can i do that? tnx in advance..


This is the code in checking the login..

<?php
$host="localhost";
$name="root";
$password="";
$db_name="records";
$tbl_name="students";

mysql_connect("$host", "$name", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$studno=$_POST['studno'];
$birthday=$_POST['birthday'];

$studno = stripslashes($studno);
$birthday =  stripslashes($birthday);

$studno = mysql_real_escape_string($studno);
$birthday = mysql_real_escape_string($birthday);

$sql="SELECT * FROM $tbl_name WHERE studno='$studno' and birthday='$birthday'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){

session_register("studno");
session_register("birthday");
header("location:selectvoter_candidates.php");
}
else {
echo "Invalid Student No. or Birthday!";
}
?>

I know that class very well, I use it in my projects (evolt.org or?)

First you need to create the user from the adminpanel provided!

Then you use

if($session->isAdmin()) the check if the user is logged in & has admin privileges

if($session->logged_in) to check if the user is logged in (simple user)

use the login form provided (login.php) and point it to process.php (<form action="process.php" method="POST">)

I know that class very well, I use it in my projects (evolt.org or?)

First you need to create the user from the adminpanel provided!

Then you use

if($session->isAdmin()) the check if the user is logged in & has admin privileges

if($session->logged_in) to check if the user is logged in (simple user)

use the login form provided (login.php) and point it to process.php (<form action="process.php" method="POST">)

How can i create adminpanel.?hmmm i had my admin panel already.i created it first before the students info..Could you use codes?so that i can easily understand what you have wanna say..tnx in adnvance..

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.