Jump to content

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.
Link to comment
https://forums.phpfreaks.com/topic/5588-help-with-my-login-system/
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]
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
[!--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]
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.