Thesus Posted October 16, 2006 Share Posted October 16, 2006 Well I'm trying to create a forum and have been doing so for a while, I just can never verify the user's password correctly. If they haven't been inserted into the database, it automatically assumes the names and password do not match. I thought I finally figured it out with this simplified-down code, but currently to no avail I just get a blank page. Help's very, very, very much appreciated. :P (Just to note aswell, this isn't a register/login forum. It's where you use a name and password, and that's it- no login)[code]<?php$host="db1.awardspace.com";$username="thesus_dantee";$password="*********";$db_name="thesus_dantee";$tbl_name="regulars";mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB");$name1 = $_POST['name'];$password1 = $_POST['password'];$name = addslashes('$name1');$password = addslashes('$password1');$check = "SELECT name FROM $tbl_name WHERE name='$name'";$query = mysql_query($check);if($query == 0){$sql = "INSERT INTO $tbl_name(name, password)VALUES('$name', '$password')";$result = mysql_query($sql);echo "Successfully Posted!";}else{$check2 = "SELECT * FROM $tbl_name WHERE name='$name' AND password='$password'";$query2 = mysql_query($check2);$count = mysql_num_rows($query2);if($count == 1){$sql2="INSERT INTO $tbl_name(name, password)VALUES('$name', '$password')";$result2=mysql_query($sql2);echo "Sucessfully Posted!";}}?>[/code] Quote Link to comment Share on other sites More sharing options...
btherl Posted October 17, 2006 Share Posted October 17, 2006 The logic in your script seems odd. At the end, with $query2, you say "If the user and password exist in the database, then insert them again". That doesn't make sense. If they are already in the database, then any attempt to insert them will fail. It should probably be[code]if ($count == 1) { echo "Username and password match!";}[/code]Also, it's a good idea to check the result of your second mysql query, just in case.[code]if ($query2 === false) { die("$query2 failed: " . mysql_error());}[/code]In this case, $query2 == 0 will give you the same result. Quote Link to comment Share on other sites More sharing options...
Masna Posted October 17, 2006 Share Posted October 17, 2006 Your queries are formatted incorrectly.No {s allowed... Quote Link to comment Share on other sites More sharing options...
Thesus Posted October 17, 2006 Author Share Posted October 17, 2006 When you check the database for the name and password, and if that person has never postd before and has no information stored, it automatically assumes the name and password are incorrect and doesn't alow you to post. So the first query checks if the name is, infact there, and if it isn't it allows you to post and stores your password for the 2nd query for future postage. :DAnd thanks, I'll try, and hopefully it'll work. :p 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.