Jump to content

Archived

This topic is now archived and is closed to further replies.

Eugene

Help with my login system.

Recommended Posts

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 :(.

[code]

<?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.";
    }
?>[/code]

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

Share this post


Link to post
Share on other sites
Well, I have no idea, that is why I come here to ask for help.

Share this post


Link to post
Share on other sites
[code] if($user == $usernames) {
    if($pass == $passwords) {[/code]

Remove the "s"s

Share this post


Link to post
Share on other sites
You just don't get it. I tried that, I tried everything possible but obviously it doesn't work!

Share this post


Link to post
Share on other sites
[code]$query = "SELECT * FROM users WHERE `username`='".$username."'";[/code]
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.

[code]$username = $_POST['user'];[/code]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[!--quoteo(post=357765:date=Mar 23 2006, 03:36 PM:name=shaunk)--][div class=\'quotetop\']QUOTE(shaunk @ Mar 23 2006, 03:36 PM) [snapback]357765[/snapback][/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 :)

[code]
<?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";
}
?>
[/code]

Share this post


Link to post
Share on other sites

×

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.