Fearpig Posted May 2, 2007 Share Posted May 2, 2007 Hi Guys can someone help me with this if / else statement? I've spent the last couple of days going through tutorials and I just can't get this to work! Whatever password I enter on the page before my if/else statement accepts it and displays "Good password and correct division", can anyone see where I'm going wrong? <?php $Event_ID = $_POST['Event_ID']; $Division = $_POST['Division']; $Password = $_POST['Password']; $sql = "SELECT * FROM tbl_Contacts WHERE Division = '$Division' AND Password = '$Password'"; if ($result = odbc_exec($conn,$sql)) { if (odbc_num_rows($result)) { echo "Good password and correct division"; } else { echo "Bad password or incorrect division"; } } ?> Link to comment https://forums.phpfreaks.com/topic/49625-solved-if-else-statement/ Share on other sites More sharing options...
jitesh Posted May 2, 2007 Share Posted May 2, 2007 <?php $result = odbc_exec($conn,$sql); if ($result) { if (odbc_num_rows($result)) { echo "Good password and correct division"; } else { echo "Bad password or incorrect division"; } } ?> Link to comment https://forums.phpfreaks.com/topic/49625-solved-if-else-statement/#findComment-243317 Share on other sites More sharing options...
Fearpig Posted May 2, 2007 Author Share Posted May 2, 2007 Hi Jitesh, Did you mean like this.... <?php $sql = "SELECT * FROM tbl_Contacts WHERE Division = '$Division' AND Password = '$Password'"; $result = odbc_exec($conn,$sql); if ($result) { if (odbc_num_rows($result)) { echo "Good password and correct division"; } else { echo "Bad password or incorrect division"; } } ?> If so it does the same thing... regardless of the password entered it gives "Good password and correct division". I can put the stored passwords and division into variables so is there a method of doing something like this?: <?php if (($Password == $Stored_Password) and ($Division == $Stored_Division)){ echo "Good password and correct division"; } else { echo "Bad password or incorrect division"; } } ?> Link to comment https://forums.phpfreaks.com/topic/49625-solved-if-else-statement/#findComment-243321 Share on other sites More sharing options...
Fearpig Posted May 2, 2007 Author Share Posted May 2, 2007 AAAAAGGGGGGGHHHHHHH!!!!!!!!!!! Found the problem! I had a password field length of 10, storing a 4 character password to test it with. When I reduced the field length to 4 the script worked first time! I'll now set up the admin page so that the passwords have to fill the field they are saved into. Link to comment https://forums.phpfreaks.com/topic/49625-solved-if-else-statement/#findComment-243330 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.