Eugene Posted March 23, 2006 Share Posted March 23, 2006 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: <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. Quote Link to comment Share on other sites More sharing options...
annihilate Posted March 23, 2006 Share Posted March 23, 2006 Where are you defining $username ? Quote Link to comment Share on other sites More sharing options...
Eugene Posted March 23, 2006 Author Share Posted March 23, 2006 Well, I have no idea, that is why I come here to ask for help. Quote Link to comment Share on other sites More sharing options...
ober Posted March 23, 2006 Share Posted March 23, 2006 [code] if($user == $usernames) { if($pass == $passwords) {[/code]Remove the "s"s Quote Link to comment Share on other sites More sharing options...
Eugene Posted March 23, 2006 Author Share Posted March 23, 2006 You just don't get it. I tried that, I tried everything possible but obviously it doesn't work! Quote Link to comment Share on other sites More sharing options...
annihilate Posted March 23, 2006 Share Posted March 23, 2006 [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] Quote Link to comment Share on other sites More sharing options...
shaunk Posted March 23, 2006 Share Posted March 23, 2006 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 Link to comment Share on other sites More sharing options...
Prismatic Posted March 24, 2006 Share Posted March 24, 2006 [!--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: <b>$username</b>";}else{ echo "Sorry, wrong details were enterd";}?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.