Login/register

This is a discussion on "Login/register" within the PHP Forum section. This forum, and the thread "Login/register are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #41 (permalink)  
Old Jul 30th, 2007, 20:34
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,790
Blog Entries: 9
Thanks: 0
Thanked 2 Times in 2 Posts
Re: Login/register

yes:

PHP: Select all

<?php
require_once('/User/connectweb.php');
$form "<form action="/User/login.php" method=\"post\">Username:<br><input type=\"text\" name=\"user\"><br>Password:<br> <input type=\"password\" name=\"pass\"><br> <p align=\"center\"><input type=\"submit\" action=\"submit\" name=\"login\" value=\"login\"> </p> </form><p>Haven't got an account? Register</p><p>Forgot your password?</p>";
 
    if (!isset(
$_SESSION['usersession'])){
echo 
$form
} else {
$doquery=mysql_query("select * from users where username='$username'");
echo 
mysql_error();
while(
$nt=mysql_fetch_array($doquery)){
echo 
"hello $nt[username]";
}
}
    
?>

is the query correct?
i wasn't too sure on it
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #42 (permalink)  
Old Jul 30th, 2007, 20:48
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,790
Blog Entries: 9
Thanks: 0
Thanked 2 Times in 2 Posts
Re: Login/register

okay, i don't get a blank page anymore but it doesn't change when the user logs in:
PHP: Select all

   <?php
$form 
"<form action=\"/User/login.php\" method=\"post\">Username:<br><input type=\"text\" name=\"user\"><br>Password:<br> <input type=\"password\" name=\"pass\"><br> <p align=\"center\"><input type=\"submit\" action=\"submit\" name=\"login\" value=\"login\"> </p> </form><p>Haven't got an account? Register</p><p>Forgot your password?</p>";
    
    if (!isset(
$_SESSION['usersession'])){
echo 
$form;
} else {
$doquery=mysql_query("select * from users where username='$username'");
echo 
mysql_error();
while(
$nt=mysql_fetch_array($doquery)){
echo 
"hello $nt[username]";
}
}

    
?>
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #43 (permalink)  
Old Jul 30th, 2007, 23:29
Reputable Member
Join Date: Jun 2007
Location: UK
Age: 29
Posts: 172
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Login/register

ok try this

on every page, at the top, put:
print_r ($_SESSION);
tell me what you get, if anything.
Reply With Quote
  #44 (permalink)  
Old Jul 30th, 2007, 23:32
Reputable Member
Join Date: Jun 2007
Location: UK
Age: 29
Posts: 172
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Login/register

and also, try to make it more obvious what you are looking for, i.e

<?php
$form
= "<form action=\"/User/login.php\" method=\"post\">Username:<br><input type=\"text\" name=\"user\"><br>Password:<br> <input type=\"password\" name=\"pass\"><br> <p align=\"center\"><input type=\"submit\" action=\"submit\" name=\"login\" value=\"login\"> </p> </form><p>Haven't got an account? Register</p><p>Forgot your password?</p>";

if (!isset(
$_SESSION['usersession'])){
echo
$form;
echo "TEST 1";
} else {//IS logged in
$doquery=mysql_query("select * from users where username='$username'");
echo "TEST 2";
echo
mysql_error()
or die(mysql_error() );
while(
$nt=mysql_fetch_array($doquery)){
echo
"hello $nt[username]";
}
}

?>

Last edited by Voodoochilli; Jul 30th, 2007 at 23:36.
Reply With Quote
  #45 (permalink)  
Old Jul 30th, 2007, 23:55
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,790
Blog Entries: 9
Thanks: 0
Thanked 2 Times in 2 Posts
Re: Login/register

Array ( [usersession] => [count] => 593 )
count was a little test i did to check if sessions where working.
and i will try that other one now thanks
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #46 (permalink)  
Old Jul 30th, 2007, 23:56
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,790
Blog Entries: 9
Thanks: 0
Thanked 2 Times in 2 Posts
Re: Login/register

only test 1 appeared.
does that mean there's something wrong with the query?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #47 (permalink)  
Old Jul 30th, 2007, 23:59
Reputable Member
Join Date: Jun 2007
Location: UK
Age: 29
Posts: 172
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Login/register

Quote:
Originally Posted by alexgeek View Post
only test 1 appeared.
does that mean there's something wrong with the query?
it means the php interpreter isnt getting to that bit, meaning, your code is broken before that point. ie after TEST 1 and before TEST 2, so we know where the problem is!
Reply With Quote
  #48 (permalink)  
Old Jul 31st, 2007, 00:01
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,790
Blog Entries: 9
Thanks: 0
Thanked 2 Times in 2 Posts
Re: Login/register

yes and the part between is:

PHP: Select all

$doquery=mysql_query("select * from users where username='$username'"); 

Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #49 (permalink)  
Old Jul 31st, 2007, 00:04
Reputable Member
Join Date: Jun 2007
Location: UK
Age: 29
Posts: 172
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Login/register

try changing
$doquery=mysql_query("select * from users where username='$username'");
to
echo "test 3";
if that works then we know there a MYSQL error. Also don't you use a mysql link identifier, I mean my mysql quries look like:

mysql_query("select * from users where username='$username'", $dl );
Reply With Quote
  #50 (permalink)  
Old Jul 31st, 2007, 00:09
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,790
Blog Entries: 9
Thanks: 0
Thanked 2 Times in 2 Posts
Re: Login/register

i don't know what a link identifier does to be honest.
and umm changing it to echo test 3 made no difference :/
PHP: Select all

if (!isset($_SESSION['usersession'])){
echo 
$form;
echo 
"TEST 1";
} else {
//IS logged in
echo "test 3";
echo 
"TEST 2";
echo 
mysql_error() or die(mysql_error() );
while(
$nt=mysql_fetch_array($doquery)){
echo 
"hello $nt[username]";
}

also,
you know in this part:
Array ( [usersession] => [count] => 593 )
does that mean that usersession doesn't contain anything?
should't it say something like [usersession] = alex
?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #51 (permalink)  
Old Jul 31st, 2007, 00:30
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,790
Blog Entries: 9
Thanks: 0
Thanked 2 Times in 2 Posts
Re: Login/register

ahh in the login script, i didn't assign the $username variable to anything.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #52 (permalink)  
Old Jul 31st, 2007, 00:56
Reputable Member
Join Date: Jun 2007
Location: UK
Age: 29
Posts: 172
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Login/register

I will have to check this tomorrow, its too late for me to think php right now (2 am) Promise I will have a think in the morning for you.
Reply With Quote
  #53 (permalink)  
Old Jul 31st, 2007, 00:57
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,790
Blog Entries: 9
Thanks: 0
Thanked 2 Times in 2 Posts
Re: Login/register

sorry to keep you up!
thank you!
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #54 (permalink)  
Old Jul 31st, 2007, 10:19
Reputable Member
Join Date: Jun 2007
Location: UK
Age: 29
Posts: 172
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Login/register

morning

ok Array ( [usersession] => [count] => 593 ) means there is something stored in it. print_r() is very useful to know if an array contains anything.

putting that in:
echo "test 3";
echo
"TEST 2";

was silly of me, must have been tired. you only need 1 echo.

can you echo the $username variable at the top to make sure it contains something ?
Reply With Quote
  #55 (permalink)  
Old Jul 31st, 2007, 10:20
Reputable Member
Join Date: Jun 2007
Location: UK
Age: 29
Posts: 172
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Login/register

also shouldn't echo "hello $nt[username]";
be
echo "hello $nt['username']";

Does it even echo the hello part?
Reply With Quote
  #56 (permalink)  
Old Jul 31st, 2007, 10:33
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,790
Blog Entries: 9
Thanks: 0
Thanked 2 Times in 2 Posts
Re: Login/register

right i've changed the session to "loggedin"
adding the '' to the echo made a blank page, and i don't know why i have a blank page because my php.ini says to display errors. anyway this is the code i'm using: (still not sure if the query is right.)

PHP: Select all

<?php
  $form 
"<form action=\"/User/login.php\" method=\"post\">Username:<br><input type=\"text\" name=\"user\"><br>Password:<br> <input type=\"password\" name=\"pass\"><br> <p align=\"center\"><input type=\"submit\" action=\"submit\" name=\"login\" value=\"login\"> </p> </form><p>Haven't got an account? <a href=\"\User\/register.php\">Register</a></p><p>Forgot your password?</p>";
  
$username $_SESSION['loggedin'];

if (!isset(
$_SESSION['loggedin'])){
echo 
$form;
} else {
//IS logged in
$doquery mysql_query("select * from users where username=$username");
echo 
mysql_error() or die(mysql_error() );
while(
$nt=mysql_fetch_array($doquery)){
echo 
"hello $nt['username']";
}
}

?>
logging in is working, but the "else" part has problems
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #57 (permalink)  
Old Jul 31st, 2007, 10:40
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,790
Blog Entries: 9
Thanks: 0
Thanked 2 Times in 2 Posts
Re: Login/register

right new one.
this is sort of working.
i think there's a problem with the "while" part though :/

PHP: Select all

 <?php
  $form 
"<form action=\"/User/login.php\" method=\"post\">Username:<br><input type=\"text\" name=\"user\"><br>Password:<br> <input type=\"password\" name=\"pass\"><br> <p align=\"center\"><input type=\"submit\" action=\"submit\" name=\"login\" value=\"login\"> </p> </form><p>Haven't got an account? <a href=\"\User\/register.php\">Register</a></p><p>Forgot your password?</p>";
  
$username $_SESSION['loggedin'];

if (!isset(
$_SESSION['loggedin'])){
echo 
$form;
} else {
//IS logged in
$thequery="select * from users WHERE username='$username'";
$doquery=mysql_query($thequery);
echo 
mysql_error() or die(mysql_error() );
while(
$nt=mysql_fetch_array($doquery)){
echo 
"hello $nt[username]";
}
}

?>
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #58 (permalink)  
Old Jul 31st, 2007, 10:56
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,790
Blog Entries: 9
Thanks: 0
Thanked 2 Times in 2 Posts
Re: Login/register

got it working

PHP: Select all

  <?php

//Database Information

$dbhost "localhost";
$dbname "web";
$dbuser "alex";
$dbpass "pass";

//Connect to database

mysql_connect $dbhost$dbuser$dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

  
$form "<form action=\"/User/login.php\" method=\"post\">Username:<br><input type=\"text\" name=\"user\"><br>Password:<br> <input type=\"password\" name=\"pass\"><br> <p align=\"center\"><input type=\"submit\" action=\"submit\" name=\"login\" value=\"login\"> </p> </form><p>Haven't got an account? <a href=\"\User\/register.php\">Register</a></p><p>Forgot your password?</p>";
  
$username $_SESSION['loggedin'];

if (!isset(
$_SESSION['loggedin'])){
echo 
$form;
} else {
$query "SELECT * FROM users WHERE username='alexgeek' ";

$result mysql_query($query) or die(mysql_error());


// Print out the contents of each row into a table 
while($row mysql_fetch_array($result)){
    echo 
$row['username']. " - "$row['score'];
    echo 
"<br />";
}
}
?>
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #59 (permalink)  
Old Jul 31st, 2007, 11:12
Reputable Member
Join Date: Jun 2007
Location: UK
Age: 29
Posts: 172
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Login/register

$query = "SELECT * FROM users WHERE username='alexgeek' ";

$result = mysql_query($query) or die(mysql_error());


// Print out the contents of each row into a table
while($row = mysql_fetch_array($result)){
echo
$row['username']. " - ". $row['score'];
echo
"<br />";

ha! you did the 2 things I was going to suggest! Put the or die in the query, not after, then add '' to the var name!
Reply With Quote
  #60 (permalink)  
Old Jul 31st, 2007, 11:12
Reputable Member
Join Date: Jun 2007
Location: UK
Age: 29
Posts: 172
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Login/register

glad its sorted (again!)
Reply With Quote
Reply

Tags
alexgeek, cs3, dreamweaver, login, mysql, php, register

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Login Register help atlaskid PHP Forum 6 Nov 10th, 2006 21:34
some type of member login/register system Lucid. Web Page Design 22 Feb 3rd, 2006 17:19


All times are GMT. The time now is 08:04.