Jump to content


Photo

Help with my login system.


  • Please log in to reply
7 replies to this topic

#1 Eugene

Eugene
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 23 March 2006 - 01:42 PM

I made a registration system which works fine here:

[a href=\"http://gfd.runeguide.co.uk/test/register.php\" target=\"_blank\"]http://gfd.runeguide.co.uk/test/register.php[/a]

It all sends the data to mysql database, but when I try and retrieve it, nothing happens. Please help me :(.


<?PHP
// Make a MySQL Connection
$link = mysql_connect("test", "test", "test") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());

$query = "SELECT * FROM users WHERE `username`='".$username."'";
$SQLdata = mysql_query($query, $link);
$record = mysql_fetch_assoc($SQLdata);


$user = $_POST['user'];
$pass = $_POST['pass'];

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



if($user == $username) {
    if($pass == $password) {
        echo "You are now logged in as:&nbsp;<b>";
        echo $_POST['user'];
        echo "</b>.";
        }
        else {
        echo "Sorry the password you entered was wrong";
    }
}
else
    {
    echo "Sorry, we could not log you in.";
    }
?>

I have tried everything, changing this and changing that and using an "AND" to that mysql query. Nothing.

#2 annihilate

annihilate
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts
  • LocationUK

Posted 23 March 2006 - 03:28 PM

Where are you defining $username ?
Personal site: NewEnigma  |  Java and JSF Discussion

#3 Eugene

Eugene
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 23 March 2006 - 04:02 PM

Well, I have no idea, that is why I come here to ask for help.

#4 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 23 March 2006 - 04:05 PM

if($user == $usernames) {
    if($pass == $passwords) {

Remove the "s"s

Info: PHP Manual


#5 Eugene

Eugene
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 23 March 2006 - 06:54 PM

You just don't get it. I tried that, I tried everything possible but obviously it doesn't work!

#6 annihilate

annihilate
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts
  • LocationUK

Posted 23 March 2006 - 07:18 PM

$query = "SELECT * FROM users WHERE `username`='".$username."'";
You are querying the database for the variable username but nowhere in the code you posted is the variable defined. If you want it to query from the submitted form data, you need to put something like this before the query.

$username = $_POST['user'];

Personal site: NewEnigma  |  Java and JSF Discussion

#7 shaunk

shaunk
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 23 March 2006 - 08:36 PM

OK, I'm a Newbie aswell but I've learn't alot over the last week and managed to get a flight logging system up an running even though it took me 10x the amount of time it would take some pro's, anyway hopefully this will help some:-

While I was setting up everything I used mysqlfront program to monitor the results being entered into my database which not only allowed me to run test pages but also allowed me to see the results in a raw format along the way and test my formulas.

So you can go get mysqlfront from [a href=\"http://www.mysqlfront.de/\" target=\"_blank\"]http://www.mysqlfront.de/[/a] and then you ahve a way to see the direct data while you enter it as a test.

Then create a recordset (let me know if you don;t know how) which should give you a subset of the main database.

At least with mysqlfront you will see your complete database directly and therefore you can figure out your query code checking the output.

Best rgds Shaun

#8 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 24 March 2006 - 01:14 AM

[!--quoteo(post=357765:date=Mar 23 2006, 03:36 PM:name=shaunk)--][div class=\'quotetop\']QUOTE(shaunk @ Mar 23 2006, 03:36 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
OK, I'm a Newbie aswell but I've learn't alot over the last week and managed to get a flight logging system up an running even though it took me 10x the amount of time it would take some pro's, anyway hopefully this will help some:-

While I was setting up everything I used mysqlfront program to monitor the results being entered into my database which not only allowed me to run test pages but also allowed me to see the results in a raw format along the way and test my formulas.

So you can go get mysqlfront from [a href=\"http://www.mysqlfront.de/\" target=\"_blank\"]http://www.mysqlfront.de/[/a] and then you ahve a way to see the direct data while you enter it as a test.

Then create a recordset (let me know if you don;t know how) which should give you a subset of the main database.

At least with mysqlfront you will see your complete database directly and therefore you can figure out your query code checking the output.

Best rgds Shaun
[/quote]


Or he could just try running this :)

<?php
$user = $_POST['user'];
$pass = $_POST['pass'];

// Make a MySQL Connection
$link = @mysql_connect("test", "test", "test") or die(mysql_error());
$db_selected = mysql_select_db("test", $link) or die(mysql_error());

$query = "SELECT * FROM users WHERE username = '$user' AND password = '$pass'";

$SQLdata = mysql_query($query);
$record = mysql_fetch_array($SQLdata);

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

if($record){
    echo "You are now logged in as:&nbsp;<b>$username</b>";
}
else{
    echo "Sorry, wrong details were enterd";
}
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users