Jump to content

Help plz


errietta

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

Archived

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

×
×
  • Create New...