Ok, so I built this MySQL based login file, from scratch. It connects to the database and fetches data from the tables. Everything works except it always defaults to your login has failed. Could anyone help me fix this? Thanks.
Code for login.php:
Code for the include, util.php:PHP Code:<?php
//FORM DATA
$user2 = Trim($_POST[user]);
$pass = Trim($_POST[pass]);
//MySQL Data
require("util.php");
$sql = new MySQL_class;
$sql->Create("demiur_helpdesk");
//check users
if ($users != "") {
$sql->Query("select users from helpdesk");
for ($i = 0; $i < $sql->rows; $i++) {
if ($exists == "1") {
break;
}
$sql->Fetch($i);
$users = $sql->data[0];
if ($user2 == $users) {
$exists = "1";
}
if ($user2 != $users) {
$exists = "0";
}
if($exists == "0"){
header("Location: index.php?login=false");
exit;
} else {
header("Location:index.php?login=false");
}
}
}
//check password
$sql->Query("select pass from helpdesk");
for ($i = 0; $i < $sql->rows; $i++) {
$sql->Fetch($i);
$passwd = $sql->data[1];
if ($pass == $passwd) {
session_start();
$_SESSION['auth'] == "true";
$_SESSION['user'] = $users;
header("Location: index2.php");
} else {
header("Location: index.php?login=false");
}
}
exit;
die;
?>
If anyone could fix this, it would be most appreciated. Thanks!PHP Code:<?
/*
* Utility routines for MySQL.
*/
class MySQL_class {
var $db, $id, $result, $rows, $data, $a_rows;
var $user, $pass, $host;
/* Make sure you change the USERNAME and PASSWORD to your name and
* password for the DB
*/
function Setup ($user, $pass, $host, $db) {
$this->user = $user;
$this->pass = $pass;
$this->host = $host;
$this->db = $db;
}
function Create ($db) {
if (!$this->user) {
# Set this to your default username
$this->user = "demiur_helpdesk";
}
if (!$this->pass) {
# Set this to your default password
$this->pass = "me1234";
}
if (!$this->host) {
# Set this to your default database host
$this->host = "localhost";
}
if (!$this->db && !$db) {
# Set this to your default database
$this->db = "demiur_helpdesk";
} else {
$this->db = $db;
}
$this->id = @mysql_pconnect($this->host, $this->user, $this->pass) or
MySQL_ErrorMsg("Unable to connect to MySQL server: $this->host : '$SERVER_NAME'");
$this->selectdb($this->db);
}
function SelectDB ($db) {
@mysql_select_db($db, $this->id) or
MySQL_ErrorMsg ("Unable to select database: $db");
}
# Use this function is the query will return multiple rows. Use the Fetch
# routine to loop through those rows.
function Query ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform query: $query");
$this->rows = @mysql_num_rows($this->result);
$this->a_rows = @mysql_affected_rows($this->id);
}
# Use this function if the query will only return a
# single data element.
function QueryItem ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform query: $query");
$this->rows = @mysql_num_rows($this->result);
$this->a_rows = @mysql_affected_rows($this->id);
$this->data = @mysql_fetch_array($this->result) or
MySQL_ErrorMsg ("Unable to fetch data from query: $query");
return($this->data[0]);
}
# This function is useful if the query will only return a
# single row.
function QueryRow ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform query: $query");
$this->rows = @mysql_num_rows($this->result);
$this->a_rows = @mysql_affected_rows($this->id);
$this->data = @mysql_fetch_array($this->result) or
MySQL_ErrorMsg ("Unable to fetch data from query: $query");
return($this->data);
}
function Fetch ($row) {
@mysql_data_seek($this->result, $row) or
MySQL_ErrorMsg ("Unable to seek data row: $row");
$this->data = @mysql_fetch_array($this->result) or
MySQL_ErrorMsg ("Unable to fetch row: $row");
}
function Insert ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform insert: $query");
$this->a_rows = @mysql_affected_rows($this->id);
}
function InsertID () {
return mysql_insert_id();
}
function Update ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform update: $query");
$this->a_rows = @mysql_affected_rows($this->id);
}
function Delete ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform Delete: $query");
$this->a_rows = @mysql_affected_rows($this->id);
}
}
/* ********************************************************************
* MySQL_ErrorMsg
*
* Print out an MySQL error message
*
*/
function MySQL_ErrorMsg ($msg) {
# Close out a bunch of HTML constructs which might prevent
# the HTML page from displaying the error text.
echo("</ul></dl></ol>\n");
echo("</table></script>\n");
# Display the error message
$text = "<font color=\"#ff0000\" size=+2><p>Error: $msg :";
$text .= mysql_error();
$text .= "</font>\n";
die($text);
}
?>![]()






Bookmarks