errietta Posted January 24, 2008 Share Posted January 24, 2008 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 More sharing options...
Ingolme Posted January 24, 2008 Share Posted January 24, 2008 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 More sharing options...
errietta Posted January 24, 2008 Author Share Posted January 24, 2008 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";......thnx <3 Link to comment Share on other sites More sharing options...
errietta Posted January 24, 2008 Author Share Posted January 24, 2008 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 More sharing options...
Ingolme Posted January 24, 2008 Share Posted January 24, 2008 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 More sharing options...
justsomeguy Posted January 24, 2008 Share Posted January 24, 2008 You need to put quotes around the username, you need to do that with any string. $d = mysql_query("SELECT password FROM users WHERE user_name='{$n}'"); Link to comment Share on other sites More sharing options...
errietta Posted January 25, 2008 Author Share Posted January 25, 2008 now it brings Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/www/pokemonlake.100webspace.net/welcome2.php on line 17 k sorry for not being able to solve this but u should know im a noob Link to comment Share on other sites More sharing options...
Synook Posted January 26, 2008 Share Posted January 26, 2008 Try echo mysql_error(); after the mysql_query() statement. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.