Jump to content

[SOLVED] Creating a member control panel


L

Recommended Posts

  • Replies 76
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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";
}
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

alright, i changed the url....sweet...i owe all of you for helping me out: pocobueno, cooldude, and mmarif4u....i think it's been two hours around since I started this topic! I really appreciate the effort in helping a fellow member of the php community, :D

 

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.