dexter_sherban Posted April 23, 2007 Share Posted April 23, 2007 I have a program that takes a value from a column and stores it into a variable. Then takes a value the user entered in a html form and stores it in another variable. Then it should see if they are the same(they are both strings). The site works, but I kept getting them unequal. And when I was tesing it I knew the valuse were equal. So I echoed them before the comparison and both are "aaaa". But the if statement sais they are different. The code is big so il try to but only the relevant lines. <?php if (isset($_POST['actualusername'])) { $actualusername=$_POST['actualusername']; } else { $actualusername=$_POST['actualusername']; } if (isset($_GET['username'])) { $username=$_GET['username']; } else { $username=null; } if (isset($_POST['new_password1'])) { $new_password1=$_POST['new_password1']; } else { $new_password1=null; } if (isset($_POST['new_password2'])) { $new_password2=$_POST['new_password2']; } else { $new_password2=null; } if (isset($_POST['old_password'])) { $old_password=$_POST['old_password']; } else { $old_password=null; } if (isset($_POST['initial'])) { $initial=$_POST['initial']; } else { $initial=null; } $date=date('y-m-d'); $con=mysql_connect("localhost","root","j3000"); if (!$con) { die ('could not connect: ' .mysql_error()); } mysql_select_db("partners",$con); if (isset($actualusername)) { $data=mysql_query("select * from partners where username='$actualusername'"); $row = mysql_fetch_array($data); $access_level=$row['acces_level']; $actualusername=$row['username']; $password_change=$row['password_change']; $actual_old_password=$row['password']; } if (isset($username)) { $data=mysql_query("select * from partners where username='$username'"); $row = mysql_fetch_array($data); $access_level=$row['acces_level']; $actualusername=$row['username']; $password_change=$row['password_change']; $actual_old_password=$row['password']; } ?> . . . <?php if ($password_change == 0) { echo "To activate your account you must change your password"; echo "<br>"; ?> <form action='partnersPasswordChange.php' method='POST' /> <table width="500" border="1"> <tr> <td width="200"><label for="name">Old Password:</label></td> <td width="300"><input type='password' id="textinput" name='old_password' class="textinput"/></td> </tr> <tr> <td><label for="name">New Password:</label></td> <td width="300"><input type='password' id="textinput" name='new_password1' class="textinput"/></td> </tr> <tr> <td><label for="name">Reapeat New Password:</label></td> <td width="300"><input type='password' id="textinput" name='new_password2' class="textinput"/></td> </tr> </table> <input type='hidden' name='actualusername' value='<?php echo ($username);?>'> <input type='hidden' name='initial' value=1> <input type='submit' class="buttonSubmit" value="Submit"/><br><br> </form> <?php if ($initial==1) { echo $actual_old_password; echo " "; echo $old_password; $counter=0; if($new_password1=="" || $new_password2=="" || $old_password="") { echo "Please fill in every field"; echo "<br>"; $counter++; } if($new_password1 != $new_password2) { echo "The new password you enter does not match"; echo "<br>"; $counter++; } if($old_password != $actual_old_password) { echo "The old password does not match"; echo "<br>"; $counter++; } if(strlen($new_password1) < 4 || strlen($new_password2) < 4) { echo "Password Must be longer than 4 characters"; echo "<br>"; $counter++; } if ($counter==0) { $upload=mysql_query("update partners set password='new_password1', password_change=1, password_change_date='$date' where username='$actualusername'"); } } } else { echo "This account has already been validated"; } ?> Sry its soo big, I though most of it is relevant :| Quote Link to comment https://forums.phpfreaks.com/topic/48304-solved-equal-variables-arenot-equal/ Share on other sites More sharing options...
mpharo Posted April 23, 2007 Share Posted April 23, 2007 Which line specifically are you getting a result from where they are not equal? or lines?? Quote Link to comment https://forums.phpfreaks.com/topic/48304-solved-equal-variables-arenot-equal/#findComment-236138 Share on other sites More sharing options...
steelmanronald06 Posted April 23, 2007 Share Posted April 23, 2007 sometimes i find that IF statements have to hold each rule in (). You have: if($new_password1=="" || $new_password2=="" || $old_password="") try going like this: if((!isset($new_password1)) || (!isset($new_password1)) || (!isset($new_password1)) See how I included each rule in it's own set of ()'s ?? Also, I went ahead and cleaned up the code. It normally isn't best to check a varialbe like you was, because it doesn't always catch like you want it to. Instead you use isset($variable) to see if the variable is set. If you want to see if the variable isn't set you go: !isset($variable) reading, litterally, if isn't set variable then do { } Anyways, like mpharo said, we need the exact error with line number. i'm just stabbing in the dark, but that is one of the things I seen wrong with your code. Quote Link to comment https://forums.phpfreaks.com/topic/48304-solved-equal-variables-arenot-equal/#findComment-236221 Share on other sites More sharing options...
dexter_sherban Posted April 24, 2007 Author Share Posted April 24, 2007 Thank you for your answers. My problem was with this IF statement if ( $old_password != $actual_old_password ) { echo "The old password does not match"; echo "<br>"; $counter++; } The REALY wierd thing is, ive tried setting both variables just before the if statement. $actual_old_password="eeee"; $old_password="eeee"; So know I know it doesnt have to do with variable types. But I still get them as not equal. Tried casting both to string, tried almost everything... Quote Link to comment https://forums.phpfreaks.com/topic/48304-solved-equal-variables-arenot-equal/#findComment-236920 Share on other sites More sharing options...
monk.e.boy Posted April 24, 2007 Share Posted April 24, 2007 I think you need to use strcmp or stricmp PHP is comparing the location of the string in memory, so if you did: $a = 'a'; $b = $a; Then I think ($a == $b) == true, but ($b == 'a') == false, because $b points to a location of a string that holds 'a' which is not the same location as the 'a' in the expression. this is pretty obvious if you code in c or c++... monk.e.boy Quote Link to comment https://forums.phpfreaks.com/topic/48304-solved-equal-variables-arenot-equal/#findComment-236924 Share on other sites More sharing options...
MadTechie Posted April 24, 2007 Share Posted April 24, 2007 Try <? if ( $old_password != $actual_old_password ) { echo "The old password does not match"; echo "<br>"; $counter++; echo "-Not same-<br>"; echo "OLD=[$old_password]<br>"; echo "actualOLD=[$actual_old_password]"; }else{ echo "-same-<br>"; echo "OLD=[$old_password]<br>"; echo "actualOLD=[$actual_old_password]"; } die; ?> Quote Link to comment https://forums.phpfreaks.com/topic/48304-solved-equal-variables-arenot-equal/#findComment-236925 Share on other sites More sharing options...
dexter_sherban Posted April 24, 2007 Author Share Posted April 24, 2007 OMG. two days of figuring it out... if($new_password1=="" || $new_password2=="" || $old_password="") $old_password=""....one equal...well its solved Quote Link to comment https://forums.phpfreaks.com/topic/48304-solved-equal-variables-arenot-equal/#findComment-236930 Share on other sites More sharing options...
MadTechie Posted April 24, 2007 Share Posted April 24, 2007 lol wanna click solved Quote Link to comment https://forums.phpfreaks.com/topic/48304-solved-equal-variables-arenot-equal/#findComment-236941 Share on other sites More sharing options...
monk.e.boy Posted April 24, 2007 Share Posted April 24, 2007 OMG. two days of figuring it out... if($new_password1=="" || $new_password2=="" || $old_password="") $old_password=""....one equal...well its solved Heh. Why does PHP allow you to assign inside an IF statement. Madness. The parser should check this. Python checks and throws and error if you try this. monk.e.boy Quote Link to comment https://forums.phpfreaks.com/topic/48304-solved-equal-variables-arenot-equal/#findComment-236971 Share on other sites More sharing options...
steelmanronald06 Posted April 28, 2007 Share Posted April 28, 2007 I've seen a loop once that required a variable to be set in the actual if statement. I don't remember it off hand, but I know that it had to be set there. I think some scripts can be made to depend on it. :-\ Quote Link to comment https://forums.phpfreaks.com/topic/48304-solved-equal-variables-arenot-equal/#findComment-240615 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.