Jump to content

Help plz


errietta
 Share

Recommended Posts

I wanna make a login form thingy.What ive done so far wont work here's my code

<?php$n = $_POST["username"];$p = $_POST["password"];$con = mysql_connect("hostname","user","pass");[yeah i put the right things there btw im not THAT stupid!]if (!$con)  {  die('Could not connect: ' . mysql_error());  }mysql_select_db("pokemonlake", $con);$d = mysql_query("SELECT password FROM users WHERE user_name=$n");mysql_close($con);if ($d==$p)echo "password is correct";else echo "wrong pass";?>

even if i put the correct pass it says it's wrong..is there another way to do it?

Link to comment
Share on other sites

You need to access the data once you've done the query:$d = mysql_query("SELECT password FROM users WHERE user_name=$n");$dat = mysql_fetch_array($d);if($dat['password'] == $p) {echo "Password is correct";......

Link to comment
Share on other sites

err dude it brought this now

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/www/pokemonlake.100webspace.net/welcome2.php on line 17wrong pass$d = mysql_query("SELECT password FROM users WHERE user_name=$n"); $dat = mysql_fetch_array($d); if($dat['password'] == $p) { echo "Password is correct";

Link to comment
Share on other sites

OK, I don't know exactly the problem, but I recommend adding one line of code for security and another line to show errors:$n = mysql_real_escape_string($n);$d = mysql_query("SELECT password FROM users WHERE user_name=$n");if (!$d) { echo "<br /><strong>".mysql_error()."</strong><br />"; }$dat = mysql_fetch_array($d);if($dat['password'] == $p) {echo "Password is correct";

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...