Jump to content

[SOLVED] If / Else statement


Fearpig

Recommended Posts

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

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";

  }
}
?>

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.

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.