Jump to content

[SOLVED] Creating a member control panel


L

Recommended Posts

  • Replies 76
  • Created
  • Last Reply

Yes you can see it, and yes it is in cp.php

<?php
session_start();
$userID = $_SESSION['userid'];
include ('database.php');
//Make the query to the database to get the users information
if (isset($userID)){

$query = mysql_query("SELECT * FROM users WHERE userid='$userID'")or die(mysql_error());
$row = mysql_fetch_assoc($query);

//This is example information that you could echo out.
echo '<b>Username:</b> '.$row['username'].'</b><br>';
echo '<b>Email:</b> '.$row['email'].'<br />';
echo '<b>Registration Date:</b> '.$row['date'].'</b>';
}else
{ echo "You are not authorized to access this area directly";
}
?>

maybe he's checking something....but anyway here's the new code now

<?php
session_start();
$userID = $_SESSION['userid'];
include ('database.php');
//Make the query to the database to get the users information
if ($userID>0){

$query = mysql_query("SELECT * FROM users WHERE userid='$userID'")or die(mysql_error());
$row = mysql_fetch_assoc($query);

//This is example information that you could echo out.
echo '<b>Username:</b> '.$row['username'].'</b><br>';
echo '<b>Email:</b> '.$row['email'].'<br />';
echo '<b>Registration Date:</b> '.$row['date'].'</b>';
}else
{ echo "You are not authorized to access this area directly";
}
?>

It's odd how that isn't working because in the database it says my userid is 4

Change the login page code to this:

 

<?php

session_start();
if (ISSET($_POST['sublogin']))
{
// Recreation of variables for later encryption uses the $_POST  will be replaced with the decrypted source
$username = trim($_POST['username']);
$password =  trim($_POST['password']);
$cryptpassword = md5($password);
$url = '/cp.php?user=$username';
//Connects to DB
require("database.php");
$table = "users";

$sql="SELECT username, userID FROM $table WHERE username='$username' and password='$cryptpassword'";
$result = mysql_query($sql)or die(mysql_error());

// If result matched $myusername and $mypassword, table row must be 1 row
if(mysql_num_rows($result) > 0)
{
// Registers sesions and redirect to file "login_success.php"

$storage = mysql_fetch_assoc($result);

//Sessions here
   $_SESSION['username'] = $storage['username'];
   $_SESSION['userid'] = $storage['userID'];
   
header("location: $url");
}
else 	
{
echo "Wrong Username or Password";
}
}
?>

<form action="" method="post">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr><td>Username:</td></tr><tr><td><input type="text" name="username" size="15" maxlength="30"/></td></tr>
<tr><td>Password:</td></tr><tr><td><input type="password" name="password" size="15" maxlength="30"></td></tr><tr><td>
<input type="submit" name="sublogin" value="Login" style="font-size: 8pt; color: #000000; word-spacing: 0; margin-top: 0; margin-bottom: 0" /></td></tr>
</table>
</form>

?>

 

mmarif4u - Like I said.

if you mean login.php(the one we've been working on) here it is

<?php

session_start();
if (ISSET($_POST['sublogin']))
{
// Recreation of variables for later encryption uses the $_POST  will be replaced with the decrypted source
$username = trim($_POST['username']);
$password =  trim($_POST['password']);
$cryptpassword = md5($password);
$url = '/cp.php?user=$username';
//Connects to DB
require("database.php");
$table = "users";

$sql="SELECT username, userID FROM $table WHERE username='$username' and password='$cryptpassword'";
$result = mysql_query($sql)or die(mysql_error());

// If result matched $myusername and $mypassword, table row must be 1 row
if(mysql_num_rows($result) > 0)
{
// Registers sesions and redirect to file "login_success.php"

$storage = mysql_fetch_assoc($result);

//Sessions here
   $_SESSION['username'] = $storage['username'];
   $_SESSION['userid'] = $storage['userID'];
   
header("location: $url");
}
else 	
{
echo "Wrong Username or Password";
}
}
?>

<form action="" method="post">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr><td>Username:</td></tr><tr><td><input type="text" name="username" size="15" maxlength="30"/></td></tr>
<tr><td>Password:</td></tr><tr><td><input type="password" name="password" size="15" maxlength="30"></td></tr><tr><td>
<input type="submit" name="sublogin" value="Login" style="font-size: 8pt; color: #000000; word-spacing: 0; margin-top: 0; margin-bottom: 0" /></td></tr>
</table>
</form>

?>

I selected ONLY what you needed from the query, to make sure that the tables actually existed (which they obviously did)...plus everything doesn't need to be selected, just a waste of query.

 

I also got rid of the variables storing the values from the database, and just registered the DB values straight to the sessions.

 

I also moved a few lines, that is probably what got it to work.

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.