PDA

View Full Version : help with login code... for ome reaason wont work can someone help?


ultrakilla
05-12-2006, 09:00 PM
i have been working on a game, and i am having trouble with the login(i know sad:( , but i'm learning!, and i'm looking for help:thumbsup: ). The login code is posted below! Somebody please reply and help me out.
<html>
<head>
<title>Abeo - checklogin Page</title>
<link rel="icon" href="sword.jpg" type="image/jpg">
<link rel="stylesheet" type="text/css"href="abeo.css">
</head>
<p class="top"><img src="ch1.gif" alt="ch.1 logo" width="512" height="57"></p>
<pre><img src="abeo.gif" alt="Logo" width="534" height="214"></pre>
<pre><a href="login.php">Login</a> <a href="forums/index.php">Forum</a> <a href="index.php">Main</a></pre>
<?php
$username="";
$password="";
$database="abeo";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$user=$_POST['user'];
$pass=$_POST['pass'];
$email=$_POST['email'];

$sql="SELECT * FROM user WHERE user='$user' and pass='$pass' and email='$email'";
$row = mysql_fetch_assoc(mysql_query($sql));

if( $row['user']==$user && $row['pass']==$pass){
setcookie("user", $user, time()+1800);
?>
<META HTTP-EQUIV="Refresh" CONTENT="0"; URL="controlcenter.php">
<?php
}
else{
?>
<pre>Could not log in!<pre>
<?php
}
?>

<pre><FORM><INPUT TYPE="BUTTON" VALUE="Try Again" ONCLICK="history.go(-1)"></FORM></pre>
</html>

Philipp
05-12-2006, 11:42 PM
what is your exact problem??
what happen?
what should happen?

guelphdad
05-13-2006, 01:23 AM
Can you log into mysql from your command line or shell using the information you are connecting with in this script? If so then you don't have a mysql problem. you should have the post moved to the appropriate forum (PHP).

ultrakilla
05-13-2006, 11:32 PM
i connect mysql. it login that dont work. it either says it failed, headers already sent, or just shows the page with nothing and just the html.(prob should move php)

guelphdad
05-14-2006, 04:27 PM
If it says headers already sent, then that is your problem isn't it? you can't have any information in the file before you send your headers.

Mikeo
05-14-2006, 04:52 PM
Look for any print, printf, or echo commands. Also look for
whitespaces, tabs etc. before the session_start();

GJay
05-14-2006, 05:45 PM
You can't have all the HTML at the beginning if you're going to use setcookie later on.
Either move the HTML, or use the ob_ PHP functions.
Either way, this isn't really SQL-related...

ultrakilla
05-15-2006, 08:44 PM
um... in english plz? i a little confused. the problem is it for tht most part executes sometimes no php it seems.

floridian
05-16-2006, 12:55 AM
Hi,

this is login.php page I use.
You can download complete secure application in php
from site http://www.configure-all.com/fusebox.php
and find exam.zip.

include('database_access_param.php');

$username = $_POST['username'];
$password = $_POST['password'];



$password=md5($password);



// the word password has code 5f4dcc3b5aa765d61d8327deb882cf99
//use it to create the first password for you admin user.
//insert directly in students table

//insert into students(stid, lastname, firstname, username, password, email, role) values (0, 'sergey', 'skudaev','sergeys','5f4dcc3b5aa765d61d8327deb882cf99','sergeys@yahoo.com','admin');



$auth = false; // Assume user is not authenticated

if (isset( $username ) && isset($password)) {

// Connect to MySQL

mysql_connect( $hostname, $dbuser, $dbpassword)
or die ( 'Unable to connect to server. (login)' );

// Select database on MySQL server

mysql_select_db($dbname )
or die ( 'Unable to select database.(login)' );

// Formulate the query

$sql = "SELECT * FROM students WHERE
username = '$username' AND
password = '$password'";



// Execute the query and put results in $result

$result = mysql_query( $sql )
or die ( 'Unable to execute query.' );

// Get number of rows in $result.

$num = mysql_numrows( $result );



if ( $num == 1 ) {


$auth = true;



$row=mysql_fetch_row($result);

$usero=$row[3];
$passo=$row[4];
$role=$row[6];



setcookie("user","");
setcookie("pass","");
setcookie("role","");
setcookie("pass",$passo);
setcookie("user",$usero);
setcookie("role",$role);





}

}

if ( ! $auth ) {

header("Location:index.html");


} else {


header("Location:home.php");



}
?>