Jump to content

Any reason for not logging in?


budder

Recommended Posts

Hey phpfreaks. I wonder if this script would log any of you in, because I'm not getting anywhere when trying.

The only thing that happens when i run the script and typing the login information in, is that it refreshes. There is no error in $error and that I don't understand because it should login or display the error message.

 

But maybe it's just me (:

<?php
session_start();

$dbHost		=	"s";
$dbUser		=	"u";
$dbPass		=	"u";
$dbDatabase	=	"t";

$db = mysql_connect($dbHost,$dbUser,$dbPass) or die("Unable to connect.");
mysql_select_db($dbDatabase, $db) or die(mysql_error($db));

if (isset($_POST['username'])) {
$username = trim($_POST['username']);
}	else {
$username = "";
}
if (isset($_POST['password'])) {
$password = $_POST['password'];
}	else {
$password = "";
}
if (isset($_REQUEST['redirect'])) {
$redirect = $_REQUEST['redirect'];
}	else {
$redirect = "main.php";
}

if (isset($_POST['submit'])) {
$query = "SELECT USERNAME FROM site_user WHERE username='" . mysql_real_escape_string($username, $db) . "'
 AND password = password('" . mysql_real_escape_string($password, $db) . "')
$result = mysql_query($query, $db)
if (mysql_num_rows($result) > 0) {
	$_SESSION['username'] = $username; //Line 33 that makes the error.
	$_SESSION['logged'] = 1;
	header("Refresh: 5; URL=" . $redirect);
	echo "<p>Du vil blive sendt videre om 5 sekunder.</p>";
	echo "<p>Hvis du ikke bliver sendt videre så klik <a href='" . $redirect . "'>her</a></p>";
	die();
	}
else {
$error = "<p>Du har angivet et forkert brugernavn eller kodeord. Prøv igen.</p>";
}
}
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<?php 
if (isset($error)) { echo $error; }
?>
<form action="login.php" method"post">
<table>
<tr>
<td>Username:</td>
<td><input type="text" name="username" maxlength="20" size="20" value="<?php echo $username; ?>" /> </td>
</tr><tr>
<td>Password:</td>
<td><input type="password" maxlength="20" size="20" value="<?php $password; ?>" /></td>
</tr><tr>
<td> </td>
<td>
<input type="hidden" name="redirect" value="<?php echo $redirect ?>" />
<input type="submit" name="submit" value="login" />
</tr>
</table>
</form>
</body>
</html>

 

Link to comment
Share on other sites

Hey sorry for putting the same code in that is a mistake.

I have edited the error that was present in the script.

There are no errors in my script (there is but they are not showed when running the script) but it is not working as I have in mind.

 

As I said in the start it would not login but the $error do not activate as it should if the pass or user is wrong. It's only showing blank page with this in the url: login.php?username=mahe04&redirect=&submit=login

 

Here is the code:

<?php
session_start();

$dbHost		=	"sql01.dk";
$dbUser		=	"elmerdahldk";
$dbPass		=	"rNnj5Tc2";
$dbDatabase	=	"elmerdahldk";

$db = mysql_connect($dbHost,$dbUser,$dbPass) or die("Unable to connect.");
mysql_select_db($dbDatabase, $db) or die(mysql_error($db));

if (isset($_POST['username'])) {
$username = trim($_POST['username']);
}	else {
$username = "";
}
if (isset($_POST['password'])) {
$password = $_POST['password'];
}	else {
$password = "";
}
if (isset($_REQUEST['redirect'])) {
$redirect = $_REQUEST['redirect'];
}	else {
$redirect = "main.php";
}

if (isset($_POST['submit'])) {
$query = "SELECT username FROM site_user WHERE username='" . mysql_real_escape_string($username) . "'
 AND password = password('" . mysql_real_escape_string($password) . "')";
$result = mysql_query($query, $db);
if (mysql_num_rows($result) > 0) {
	$_SESSION["username"] = $username;
	$_SESSION['logged'] = 1;
	header("Refresh: 5; URL=" . $redirect);
	echo "<p>Du vil blive sendt videre om 5 sekunder.</p>";
	echo "<p>Hvis du ikke bliver sendt videre så klik <a href='" . $redirect . "'>her</a></p>";
	die();
	}
else {
$error = "<p>Du har angivet et forkert brugernavn eller kodeord. Prøv igen.</p>";
}
}
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<?php 
if (isset($error)) { echo $error; }
?>
<form action="login.php" method"post">
<table>
<tr>
<td>Username:</td>
<td><input type="text" name="username" maxlength="20" size="20" value="<?php echo $username; ?>" /> </td>
</tr><tr>
<td>Password:</td>
<td><input type="password" maxlength="20" size="20" value="<?php $password; ?>" /></td>
</tr><tr>
<td> </td>
<td>
<input type="hidden" name="redirect" value="<?php echo $redirect ?>" />
<input type="submit" name="submit" value="login" />
</tr>
</table>
</form>
</body>
</html>

 

Yes it look like the same code, the difference is that there is no error even when there should be.

If the username and password is invaild it should show the $error message.

 

 

Link to comment
Share on other sites

You're missing an equals sign.

Damnit, the copying screwed up, here it is:

<form action="login.php" method="post"> <!-- HERE YOU MISSED AN EQUALS DEFAULTING TO GET -->
<table>
<tr>
<td>Username:</td>
<td><input type="text" name="username" maxlength="20" size="20" value="<?php echo $username; ?>" /> </td>
</tr><tr>
<td>Password:</td>
<td><input type="password" maxlength="20" size="20" value="<?php $password; ?>" /></td>
</tr><tr>
<td> </td>
<td>
<input type="hidden" name="redirect" value="<?php echo $redirect ?>" />
<input type="submit" name="submit" value="login" />
</tr>
</table>
</form>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.