...

View Full Version : Login Right But Says Its Wrong



night_hawk
07-03-2007, 08:28 PM
I have made this code but for some reason it doesnt login i dont understand why

<?
ob_start();
mysql_connect('localhost', 'xxx', 'xxx');
mysql_select_db('xxx');
if($_POST['login']){
if(!$_POST['username'] && !$_POST['password']){
$log = "Please Supply A Username And Password";
}
else{
$user = $_POST['username'];
$pass = $_POST['passwprd'];
$query = "SELECT username, password, status FROM users WHERE username='$user' AND password='$pass'";
$fetch = mysql_query($query)or die(mysql_error());
$result = mysql_fetch_array($fetch);
if($result){
if($result['status'] == 0){
session_start();
$_SESSION['user'] = $user;
header('location: index.php?page=activate');
}
else{
session_start();
$_SESSION['user'] = $user;
header('location: index.php?page=base');
}
}
else{
$log = "Wrong Username or Password";
}
}
}
?>
<html>
<head>
<title>Chaos Fights</title>
<link rel="stylesheet" href="main.css" type="text/css" />
</head>
<body>
<table width="80%" align="center" cellpading="0" cellspacing="0">
<tr>
<td align="center"><img src="images/logo.jpg" alt="Chaos Fights" /></td></tr></table>
<table width="80%" align="center" cellpading="0" cellspacing="0">
<? if($log){
?>
<tr>
<td class="login"><?= $log; ?></tr></tr>
<?
}else{}
?>
<tr><form action="" method="post">
<td width="16%" class="login">Username:</td>
<td width="16%" class="login"><input name="username" id="username" type="text" /></td>
<td width="16%" class="login">Password:</td>
<td width="16%" class="login"><input name="password" id="password" type="password" /></td>
<td width="16%" class="login"><input name="login" id="login" type="submit" value="LogIn" /></td></tr></form></table>
<table width="80%" align="center" cellpading="0" cellspacing="0">
<tr><td class="login"><a href="?page=signup">Sign Up</a> | <a href="?page=forgot">Forgot Pass?</a></td></tr></table>
<?
if(empty($_GET['page'])){
?>
<table width="80%" align="center" cellpading="0" cellspacing="0">
<tr>
<td width="20%" class="race">Space Marines</td>
<td width="20%" class="race">Dwarves</td>
<td width="20%" class="race">Elves</td>
<td width="20%" class="race">Demons</td></tr><tr>
<td width="20%" align="center"><img src="images/sm.jpg" alt="Chaos Fights" /></td>
<td width="20%" align="center"><img src="images/dw.jpg" alt="Chaos Fights" /></td>
<td width="20%" align="center"><img src="images/ev.jpg" alt="Chaos Fights" /></td>
<td width="20%" align="center"><img src="images/de.jpg" alt="Chaos Fights" /></td></tr><tr>
<td width="20%" class="race">Gather your troops to fight the coming horde! </td>
<td width="20%" class="race">Come to the aid of your allies and destroy your enemies! </td>
<td width="20%" class="race">Harness your strength and fight for your people! </td>
<td width="20%" class="race">Use your might to spread evil throughout the land!</td></tr><tr>
<td width="20%" class="race">25% Income Bonus</td>
<td width="20%" class="race">30% Defense Bonus </td>
<td width="20%" class="race">35% Spy Bonus </td>
<td width="20%" class="race">30% Attack Bonus </td></tr></table><br><br><br><br><br>
<table width=80% cellspacing=0 cellpading=0 align="center">
<tr>
<td class="news">Updates</td></tr></table>
<table width=80% cellspacing=0 cellpading=0 align="center">
<tr>
<td class="update">June 18th 2007:</td></tr><tr>
<td class="update">Chaos Fights V2 Started</td></tr></table>
<?
}
else{
switch($_GET['page']){
case "signup":
require_once "register.php";
break;
case "activate":
require_once "activate.php";
break;
}
}
?>
<br><br><br>
<table width=80% cellspacing=0 cellpading=0 align="center">
<tr>
<td class="copyright">&copy; Chaos Fights Owned And Ran By: <a href="http://ewnetwork.info/" target="_blank">EW Network</a></td></tr></table>

</body>
</html>

PappaJohn
07-03-2007, 09:01 PM
At first glance:

1.


if(!$_POST['username'] && !$_POST['password'])

This condition will only be true if no username AND no password has been set. I think you mean:


if(!$_POST['username'] || !$_POST['password'])

1.
Typo here:


$pass = $_POST['passwprd'];

fl00d
07-03-2007, 10:40 PM
yeah thats the only two things I noticed which were wrong. Fix those two things PappaJohn pointed out and it should all work smoothly.

night_hawk
07-03-2007, 10:44 PM
Thanks Alot It Worked :) thanks again



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum