Viewing topic:Registration Help Needed
Page:
1
04-08-2008 - 2:28
Hello,
First of all id just like to say that this is easily the best tutorial site that i have ever seen. I just found it a few hours ago and its a major blessing.
Well on to my problem, ok i got the registering to work, i think, but whenever i try to login it says 'Please login before opening the user panel.' ive tried everything i know, which really isnt all that much lol, and i cant seem to get it to work.
im sorry if this has been asked before but i couldnt find it in the forums, and thanks for any help in advance.
First of all id just like to say that this is easily the best tutorial site that i have ever seen. I just found it a few hours ago and its a major blessing.
Well on to my problem, ok i got the registering to work, i think, but whenever i try to login it says 'Please login before opening the user panel.' ive tried everything i know, which really isnt all that much lol, and i cant seem to get it to work.
im sorry if this has been asked before but i couldnt find it in the forums, and thanks for any help in advance.
04-08-2008 - 13:38
Hi pyrosent, welcome to CM
. Glad you like it.
About your problem, can you please post your soure, you can use the [code] bb tags. The first thing I can think of is that your session is not set.
. Glad you like it.About your problem, can you please post your soure, you can use the [code] bb tags. The first thing I can think of is that your session is not set.
04-08-2008 - 14:33
ok, here is the registration, login, and userpanel cod just in case:
once again thanks for any help.
| code | |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
<?php
$db_host = "******"; // mySQL database host
$db_user = "users"; // mySQL database user
$db_password = "******"; // mySQL database password
$db_name = "users"; // the name of your mySQL database
$conn = mysql_connect($db_host,$db_user,$db_password) or die(mysql_error());
mysql_select_db($db_name);
// is ?try=true in the url?
if (isset($_GET['try'])) {
// Yes, the user has clicked on the submit button, let's check if he filled in all the fields
if(empty($_POST['username']) OR
empty($_POST['password']) OR
empty($_POST['email']) ) {
// At least one of the file is empty, display an error
echo 'You haven't filled in all the fields. Please do it again.';
} else {
// User has filled it all in!
// SQL save variables
$username = mysql_real_escape_string($_POST['username']);
$password = MD5($_POST['password']);
$email = mysql_real_escape_string($_POST['email']);
$query = mysql_query("SELECT COUNT(id) FROM users
WHERE username = '" . $username . "'
OR email = '" . $email . "' ") or die(mysql_error());
list($count) = mysql_fetch_row($query);
if($count == 0) {
// Username and Email are free!
mysql_query("INSERT INTO users
(username, password, email)
VALUES
('" . $username . "', '" . $password . "', '" . $email . "')
") or die(mysql_error());
echo 'You are successfully registered!';
} else {
// Username or Email already taken
echo 'Username or Email address already taken!';
}
}
}
?>
<form action="register.php?try=true" method="post">
Username: <input type="text" name="username"><br>
<br>
Password: <input type="password" name="password"><br>
<br>
Email: <input type="text" name="email"><br>
<br>
<input type="submit" value="register">
</form>
|
| code | |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
<?php
$conn = mysql_connect('******', 'users', '******') or die(mysql_error());
mysql_select_db('users', $conn);
// Start the session (DON'T FORGET!!)
session_start();
// Check if user wants to login (GET info)
if(isset($_GET['try'])) {
// That's nice, user wants to login. But lets check if user has filled in all information
If(empty($_POST['username']) OR empty($_POST['password'])) {
// User hasn't filled it all in!
echo 'Please fill in all the required fields!';
} else {
// User filled it all in!
// Make variables save with addslashes and md5
$username = addslashes($_POST['username']);
$password = md5($_POST['password']);
// Search for a combination
$query = mysql_query("SELECT id FROM users
WHERE username = '" . $username . "'
AND password = '" . $password . "'
") or die(mysql_error());
// Save result
list($user_id) = mysql_fetch_row($query);
// If the user_id is empty no combination was found
if(empty($user_id)) {
echo 'No combination of username and password found.';
} else {
// the user_id variable doesn't seem to be empty, so a combination was found!
// Create new session, store the user id
$_SESSION['user_id'] = $user_id;
// Redirect to userpanel.php
header('location: userpanel.php');
}
}
}
?>
<form action="login.php?try=true" method="post">
Username: <input type="text" name="username"><br>
<br>
Password: <input type="password" name="password"><br>
<br>
<input type="submit" value="Login!">
</form>
|
| code | |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<?php
// Start session
session_start();
$conn = mysql_connect('******', 'users', '******') or die(mysql_error());
mysql_select_db('users', $conn);
// Check if user is logged in
if(isset($_SESSION['user_id'])) {
// User is logged in!
$query = mysql_query("SELECT username FROM users
WHERE ID = " . $_SESSION['user_id'] . " LIMIT 1")
or die(mysql_error());
list($username) = mysql_fetch_row($query);
echo 'Hi '. $username . ', welcome to your profile!';
} else {
// User not logged in
echo 'Please login before opening the user panel.';
}
?>
|
once again thanks for any help.
04-08-2008 - 14:47
These are the files 100%? So there is no html around it, it's not included in another file etc?
Quite weird it's not working though, seems like it's pricisely the same code as from the tutorial (which works fine). Can you echo $_SESSION['user_id'] on the userpanel.php just below session_start()?
If it has no value, try die($_SESSION['user_id']); just before header('loc... on the login.php page. If this does output the user_id we're having quite a weird problem here. Prob your session settings...
Quite weird it's not working though, seems like it's pricisely the same code as from the tutorial (which works fine). Can you echo $_SESSION['user_id'] on the userpanel.php just below session_start()?
If it has no value, try die($_SESSION['user_id']); just before header('loc... on the login.php page. If this does output the user_id we're having quite a weird problem here. Prob your session settings...
04-08-2008 - 15:03
ok so when i first added the thing on the user panel it gives me a blank page, when i add the login thing it gives me my id, which is 1, and thats it.
oh and yes i have html around it but, i couldnt get it to work before hand without html either.
oh and yes i have html around it but, i couldnt get it to work before hand without html either.
04-08-2008 - 17:15
i take it that the solution to this is not going to be easy, somehow some way im sure its something that i did at some point. if there are any solutions, i would be extremely grateful. thanks again
04-08-2008 - 18:06
Hmm without HTML it isnt working either? Or else it could be the same problem as this guy: http://www.combined-minds.net/forum/topic/78/errors/
Try this code for a sec, without ANY html or text around it, even a simple space before <?php could cause the problem.
Also, could you show me the location where i can see it online?
Don't worry, well find the solution
Try this code for a sec, without ANY html or text around it, even a simple space before <?php could cause the problem.
| code | |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<?php
// Start session
session_start();
// Show all session info
print_r($_SESSION);
// Halt further execution
die();
$conn = mysql_connect('******', 'users', '******') or die(mysql_error());
mysql_select_db('users', $conn);
// Check if user is logged in
if(isset($_SESSION['user_id'])) {
// User is logged in!
$query = mysql_query("SELECT username FROM users
WHERE ID = " . $_SESSION['user_id'] . " LIMIT 1")
or die(mysql_error());
list($username) = mysql_fetch_row($query);
echo 'Hi '. $username . ', welcome to your profile!';
} else {
// User not logged in
echo 'Please login before opening the user panel.';
}
?>
|
Also, could you show me the location where i can see it online?
Don't worry, well find the solution
04-08-2008 - 18:37
ok i did that, now it says the username/password does not exist
and the actual site is here www.nabacomics.com
oh and the site is still being heavily worked on so dont mind the current layout or anything
edit: i now get Array ( ) instead
and the actual site is here www.nabacomics.com
oh and the site is still being heavily worked on so dont mind the current layout or anything

edit: i now get Array ( ) instead
04-08-2008 - 21:30
Delete those files from your server right now! First of all is that your server prob doesnt support PHP, second is that i can read all your PHP code in your html file including database passwords etc (dont worry havent read them)
Please delete them and add msn at zonax.net to your msn list and I will help you
Please delete them and add msn at zonax.net to your msn list and I will help you
06-08-2008 - 15:07
Hey Drew,
To test if PHP actually workes on your server please create a file on your server (eg test.php) with the following code:
You should see a page of about 4 200 lines in length.
To test if PHP actually workes on your server please create a file on your server (eg test.php) with the following code:
| php | |
|
1 2 3 4 5 |
<?php phpinfo(); ?> |
You should see a page of about 4 200 lines in length.
06-08-2008 - 16:06
yep ive got a whole bunch of different tables and such, at the top it even says i have php version 4.4.7
so if i have php then im guessing that it was something that i did wrong.
so if i have php then im guessing that it was something that i did wrong.
06-08-2008 - 19:41
06-08-2008 - 19:47
Page:
1
Reply to topic
Reply to topic

