Jump to content

[SOLVED] Login not working


S A N T A

Recommended Posts

ok so i have this login that when you login it redirects you to the index page BUT on the index page there is suppose to display "Logout" instead of "Login"

 

here the login code:

 

<?php

require("config.php");
session_start();

$db = mysql_connect($dbhost, $dbuser);
mysql_select_db($dbdatabase, $db);

if($_POST['submit']) {
$sql = "SELECT * FROM logins WHERE username = '" . $_POST['username'] . "' AND password = '" . $_POST['password'] . "';";

$result = mysql_query($sql);
$numrows = mysql_num_rows($result);

if($numrows == 1) {
$row = mysql_fetch_assoc($result);
session_register("USERNAME");
session_register("USERID");

$_SESSION['USERNAME'] = $row['username'];
$_SESSION['USERID'] = $row['id'];

header("Location: " . $config_basedir);
}

else {
header("Location: " . $config_basedir . "/login.php?error=1");
}
}
else {

	//require("header.php");

	if($_GET['error']) {
	echo "Incorrect login, please try again!";
	}

?>


<form action="<?php echo $SCRIPT_NAME ?>" method="post">

<table>
<tr>
<td>Username</td>
<td><input type="text" name="username"</td>
</td>
<tr>
<td>Password</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Login!"></td>
</tr>
</tr>
</table>
</form>
<?
}

?>
<?php
require("footer.php");
?>

 

here is the link code:

 

 <?php

if(isset($_SESSION['USERNAME']) == TRUE) {
	echo "<a href='logout.php'>Logout</a>";
}
else {
	echo "<a href='login.php'>Login</a>";
	}
	?>

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/103274-solved-login-not-working/
Share on other sites

Are you getting any error message?

mysql_connect($dbhost, $dbuser);

Typically, mysql_connect() should pass one more argument about the db password. Does your db have a password and you are not supplying it?

 

PS:if your db doesn't have a password, then its file to have only 2 arguments.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.