Jump to content

login error


chris_rulez001

Recommended Posts

here is the code for login.php:

 

<?php
session_start();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<?php
$host1="localhost"; // Host name
$username1="root"; // Mysql username
$password1="***"; // Mysql password
$db_name1="forum"; // Database name
$tbl_name4="thunderboardforums"; // Table name

// Connect to server and select databse.
mysql_connect("$host1", "$username1", "$password1")or die("cannot connect");
mysql_select_db("$db_name1")or die("cannot select DB");

$sql4="SELECT * FROM $tbl_name4 ORDER BY id DESC";
// OREDER BY id DESC is order result by descending
$result4=mysql_query($sql4);

$rows4 = mysql_fetch_array($result4);
?>
<title><?php echo $rows4['forumtitle']; ?> - <?php 

mysql_connect("$host1", "$username1", "$password1")or die("cannot connect");
mysql_select_db("$db_name1")or die("cannot select DB");

$sqlb="SELECT * FROM boardsetting WHERE action='boardactive'";
// OREDER BY id DESC is order result by descending
$resultb=mysql_query($sqlb);

$boardsetting = mysql_fetch_array($resultb);

$action = $_GET['action']; 

if ($action == "") 
{ 
echo "Login"; 
} 
else if ($action == "login2")
  { 
  echo "Login";
   } 
else if ($boardsetting['setting'] == 2)
{
echo "Forum Unavailable";
}
   else 
   { 
   echo "";
    } ?></title>
<link rel="stylesheet" href="css/stylesheet.css" />
</head>

<body text="000000" bgcolor="F1F1F1" link="003399" vlink="003399" alink="003399"> 
<?php
$tbl_name="boards"; // Table name

// Connect to server and select databse.
mysql_connect("$host1", "$username1", "$password1")or die("cannot connect");
mysql_select_db("$db_name1")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
// OREDER BY id DESC is order result by descending
$result=mysql_query($sql);
?>

<?php
$tbl_name1="forumusers"; // Table name

// Connect to server and select databse.
mysql_connect("$host1", "$username1", "$password1")or die("cannot connect");
mysql_select_db("$db_name1")or die("cannot select DB");

$sql1="SELECT * FROM $tbl_name1 ORDER BY id DESC";
// OREDER BY id DESC is order result by descending
$result1=mysql_query($sql1);

$rows1 = mysql_fetch_array($result1);
?>

<?php
$tbl_name2="topics"; // Table name

// Connect to server and select databse.
mysql_connect("$host1", "$username1", "$password1")or die("cannot connect");
mysql_select_db("$db_name1")or die("cannot select DB");

$sql9="SELECT * FROM $tbl_name2 ORDER BY id DESC";
// OREDER BY id DESC is order result by descending
$result9=mysql_query($sql9);

$rows9 = mysql_fetch_array($result9);
?>
<br />
<br/>
<table border="0" width="900" cellspacing="0" cellpadding="0" style="border-color:#000000" align="center">
  <tr>
    <td align='center'>My Forum<br/><br/><br/>
<< <?php 
$action = $_GET['action'];

mysql_connect("$host1", "$username1", "$password1")or die("cannot connect");
mysql_select_db("$db_name1")or die("cannot select DB");

$sqlb="SELECT * FROM boardsetting WHERE action='boardactive'";
// OREDER BY id DESC is order result by descending
$resultb=mysql_query($sqlb);

$boardsetting = mysql_fetch_array($resultb);

mysql_connect("$host1", "$username1", "$password1")or die("cannot connect");
mysql_select_db("$db_name1")or die("cannot select DB");

$sqlb1="SELECT setting FROM boardsetting WHERE action='boardmessage'";
// OREDER BY id DESC is order result by descending
$resultb1=mysql_query($sqlb1);

$boardmessage = mysql_fetch_array($resultb1);

if ($action == "") 
{ 
echo "Login"; 
} 
else if ($action == "login2")
  { 
  echo "Login";
   } 
else if ($boardsetting['setting'] == 2)
{
echo "Forum Unavailable";
}
   else 
   { 
   echo "";
    } ?> >>
</td>

    <td align='center'><?php if (!isset($_SESSION['username']) == false) { echo "Yo,  ".$_SESSION['username']."<br/><br/>You currently have no new pms,
 You have <a href='index.php?action=pm'>111 pms</a> in your inbox."; } else{
echo "Yo, Guest, Please <a href='login.php'>Login</a> or <a href='register.php'>Register</a><br/>"; }?>
 <br/><br/><?php $date = date("l F d, g i a"); echo $date; ?><br/><br/>

</td>
  </tr>
  
  <tr>
<td class="menubg" valign="middle" bgcolor="EFEFEF" align="center" colspan="2"><font size="1">
<a href="index.php">Home</a>  <a href="help.php">Help</a>  <a href="members.php">Members</a>  <a href="view_profile.php">Profile</a><?php if ($_SESSION['username'] == "admin") { echo "  <a href='admin.php'>Admin Panel</a>"; }else { echo ""; } ?>
<?php if (!isset($_SESSION['username']) == false) { echo "  <a href='logout.php'>Logout</a>"; }else {
echo "  <a href='login.php'>Login</a>  <a href='register.php'>Register</a>"; } ?>
</font></td>
</tr>
</table>

<br /><br/>
<?php
$action = $_GET['action'];

switch ($action)
{
//start of login
default:
mysql_connect("$host1", "$username1", "$password1")or die("cannot connect");
mysql_select_db("$db_name1")or die("cannot select DB");

$sqlb="SELECT * FROM boardsetting WHERE action='boardactive'";
// OREDER BY id DESC is order result by descending
$resultb=mysql_query($sqlb);

$boardsetting = mysql_fetch_array($resultb);

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

echo "<table width='92%' cellspacing='0' cellpadding='0' align='center'>
  <tr>
    <td valign='top' width='100%'>
      <br />
<a href='index.php' class='nav'>".$rows4['forumtitle']."</a> --> "; 

if ($action == "") 
{ 
echo "Login"; 
} 
else if ($action == "login2")
  { 
  echo "Login";
   } 
else if ($boardsetting['setting'] == 2)
{
echo "Forum Unavailable";
}
   else 
   { 
   echo "";
    } if ($boardsetting['setting'] == 2)
{
echo "<br/><br/>
<table border='0' width='100%' cellspacing='0' cellpadding='0'>
<tr>
<td>
<table cellpadding='4' cellspacing='1' border='0' width='100%'>";

echo "<tr>
<td class='catbg' bgcolor='DADADA' height='18'>
$boardmessage<br/><br/>
Admin Team.
</td>";

echo "</table><br/><br/>";
}
else
{	echo "<br/><br/>
<table border='0' width='100%' cellspacing='0' cellpadding='0'>
<tr>
<td>
<table cellpadding='4' cellspacing='1' border='0' width='100%'>
<tr>
<td style='background-color:DADADA' colspan='2'>
<font color='0000' size='-1'><b>Login</b></font></td>
</tr>";

echo "<tr>
<td class='catbg' bgcolor='DADADA' height='18'>
<form id='form1' name='form1' method='post' action='?action=login2'>
  <p>Username: 
    <input name='username' type='text' id='username' />
</p>
  <p>Password: 
    <input name='password' type='password' id='password' />
</p>
  <p>
    <input type='submit' name='Submit' value='Login!' />
  </p>
</form>";

echo "</td>
</tr>
</table></td>
</tr>
</table><br/><br/>";
}
break;

//end of login

case login2:
mysql_connect("$host1", "$username1", "$password1")or die("cannot connect");
mysql_select_db("$db_name1")or die("cannot select DB");

$sqlb="SELECT * FROM boardsetting WHERE action='boardactive'";
// OREDER BY id DESC is order result by descending
$resultb=mysql_query($sqlb);

$boardsetting = mysql_fetch_array($resultb);

echo "<table width='92%' cellspacing='0' cellpadding='0' align='center'>
  <tr>
    <td valign='top' width='100%'>
      <br />
<a href='index.php' class='nav'>".$rows4['forumtitle']."</a> --> "; 

if ($action == "") 
{ 
echo "Login"; 
} 
else if ($action == "login2")
  { 
  echo "Login";
   } 
else if ($boardsetting['setting'] == 2)
{
echo "Forum Unavailable";
}
   else 
   { 
   echo "";
    } if ($boardsetting['setting'] == 2)
{
echo "<br/><br/>
<table border='0' width='100%' cellspacing='0' cellpadding='0'>
<tr>
<td>
<table cellpadding='4' cellspacing='1' border='0' width='100%'>";

echo "<tr>
<td class='catbg' bgcolor='DADADA' height='18'>
$boardmessage<br/><br/>
Admin Team.
</td>";

echo "</table><br/><br/>";
}
else
{	echo "<br/><br/>
<table border='0' width='100%' cellspacing='0' cellpadding='0'>
<tr>
<td>
<table cellpadding='4' cellspacing='1' border='0' width='100%'>
<tr>
<td style='background-color:DADADA' colspan='2'>
<font color='0000' size='-1'><b>Login</b></font></td>
</tr>";

echo "<tr>
<td class='catbg' bgcolor='DADADA' height='18'>";

$username = $_POST["username"];
$password = md5($_POST["password"]);

mysql_connect("$host1", "$username1", "$password1")or die("cannot connect");
mysql_select_db("$db_name1")or die("cannot select DB");

if(mysql_real_escape_string(empty($username)))
{
echo "You havent filled all the required fields<br/><br/><a href='javascript:history.go(-1)'>Go Back</a>";
}
else if (mysql_real_escape_string(empty($password)))
{
echo "You havent filled all the required fields<br/><br/><a href='javascript:history.go(-1)'>Go Back</a>";
}
else
{	
$query = "SELECT * FROM forumusers WHERE username='$username' AND password='$password'";
$result = mysql_query($query) OR DIE("error: ".mysql_error());
mysql_close();
if (mysql_num_rows($result) > 0) {
	$r = mysql_fetch_assoc($result);
	$user = $r["username"];
	$pass = $r["password"];
	if ($username == $user && $password == $pass) {
		$_SESSION["username"] = $username;
		$loggedin = TRUE;
	}
} else {
	$loggedin = FALSE;
}
}	
}

echo "</td>
</tr>
</table></td>
</tr>
</table><br/><br/>";
break;
}
?> 
<div align="center"><?php include('includes/copyright.php'); echo $hosted; ?></div>
</body>
</html>

 

to get username and password into $_SESSION['username'] and $_SESSION['password'] couldn't i use session_register() or wouldnt that work for what i want the session to do?

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.