spaceman12 Posted December 22, 2010 Share Posted December 22, 2010 Hello guys, this is so weird, very weird indded! PHP is generating some strange problem here over with me. Below are a short context of code that I have used to make a registration script. At the first inititial stage of code testing, everything goes well so smooth according to the plans. Then, I insert the exit; function at the end of each If() functions so as to curtail off completely from further execution of the script below and thereafter. Then, suddenly all the !ISSET values stop to functions. I then removed exit(); function off from my code and restore back to the last known good working stage of my code. But it seems like the ISSET function accompanied with the !(stop operator) cease to fucntion any more ever since then even though the script exhibit the same code when it was working normally good. It makes me wonder and now i'm totally frustrated, Please help!!! Now even all the operator values like ==, !=, <, > doesnt work anymore!!! P.S. I know someone would suggest me to write if(!isset($_POST['Name'])) ......... in this format instead of $Name but as i mentioned it earlier, i'm able to execute the script using the later one as desired in accordance to what is planned. <?php $IP=$_SERVER['REMOTE_ADDR']; $Date=date('d/m/Y'); $proID=$_GET['proID']; $ref=$_GET['ref']; $Name=$_POST['Name']; $Email=$_POST['Email']; $Country=$_POST['Country']; $Username=$_POST['Username']; $Password=$_POST['Password']; $Con_Password=$_POST['Con_Password']; if(!isset($Name)) { header ('Location: reenter.php'); exit(); } if(!isset($Email)) { header ('Location: reenter.php'); exit(); } if(!isset($Country)) Quote Link to comment https://forums.phpfreaks.com/topic/222367-help-php-generating-weird-problem-working-with-the-operator/ Share on other sites More sharing options...
solon Posted December 22, 2010 Share Posted December 22, 2010 Hey spaceman12, I believe that using the isset function on a variable this way cannot be done because when you SET the variable like: $Name=$_POST['Name']; it is SET to even an empty value... but it is SET. so you will not be able to check if it has a value unless you check it like: if(!isset($_POST['Name'])) and then give its value to $Name variable or . if($Name == "") I think that is the reason your script wont work. To check that try to declare your $Name variable instead of like : $Name=$_POST['Name']; like this: $Name; and run your script. It will go in to the if statement and execute your code because the variable is actually not SET! Hope this helped. Quote Link to comment https://forums.phpfreaks.com/topic/222367-help-php-generating-weird-problem-working-with-the-operator/#findComment-1150228 Share on other sites More sharing options...
spaceman12 Posted December 22, 2010 Author Share Posted December 22, 2010 Hello salon, Thank you for the fast reply. I removed $Name and replace with the $_POST['Name'] within the parenthesis of the isset function. Its still fails to yield any positive result. To make it sure that the !ISSET function is working normally good, I have even tested this out - <?php if(!isset($_POST['Name'])) { echo "no values set" } else echo $_POST['Name']; ?> Very strangely, the output code for this is BLANK WHITE PAGE even though nothing is been entered into the field titled "Name". Quote Link to comment https://forums.phpfreaks.com/topic/222367-help-php-generating-weird-problem-working-with-the-operator/#findComment-1150230 Share on other sites More sharing options...
solon Posted December 22, 2010 Share Posted December 22, 2010 well for the last piece of code provided you are missing a semicolon ( ; ) and you must have error reporting off. try this: <?php error_reporting(E_ALL); if(!isset($_POST['Name'])) { echo "no values set"; } else echo $_POST['Name']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/222367-help-php-generating-weird-problem-working-with-the-operator/#findComment-1150231 Share on other sites More sharing options...
solon Posted December 22, 2010 Share Posted December 22, 2010 Also i tested this code and it works: First try this to see that the $Name is really set and what happens: <?php error_reporting(E_ALL); $IP=$_SERVER['REMOTE_ADDR']; $Date=date('d/m/Y'); $proID=$_GET['proID']; $ref=$_GET['ref']; //$Name variable is set to test $Name="test"; //$Email variable is set to testemail $Email="testemail"; $Country=$_POST['Country']; $Username=$_POST['Username']; $Password=$_POST['Password']; $Con_Password=$_POST['Con_Password']; if(!isset($Name)) { header ('Location: reenter.php'); exit(); } if(!isset($Email)) { header ('Location: reenter.php'); exit(); } echo $Name; ?> you will get "test" displayed and then this: <?php error_reporting(E_ALL); $IP=$_SERVER['REMOTE_ADDR']; $Date=date('d/m/Y'); $proID=$_GET['proID']; $ref=$_GET['ref']; //$Name variable is not set $Name; //$Email variable is not set $Email; $Country=$_POST['Country']; $Username=$_POST['Username']; $Password=$_POST['Password']; $Con_Password=$_POST['Con_Password']; if(!isset($Name)) { header ('Location: reenter.php'); exit(); } if(!isset($Email)) { header ('Location: reenter.php'); exit(); } echo $Name; ?> you will be redirected Quote Link to comment https://forums.phpfreaks.com/topic/222367-help-php-generating-weird-problem-working-with-the-operator/#findComment-1150232 Share on other sites More sharing options...
spaceman12 Posted December 22, 2010 Author Share Posted December 22, 2010 Thanx SOLON, Well, sorry to put the ; at the end of one of my php command line. With special reference to your comment above, yes they do work well but the ISSET has to have its function focussed on $_POST and not that the $Name has to be necessarily left as empty. however, if(empty($_POST['Name'])) this seems to be working fine and i can substitute with it but the problem is that it completely ignores all the operators embedded in my code down below. At the initial of testing period, they are 100% working fine. The problem started eversince when I alter the IF() function with EXIT; . Also, I use multiple IF() function in my script. Now, i begin to wonder if the php has to do with some virus as well. Quote Link to comment https://forums.phpfreaks.com/topic/222367-help-php-generating-weird-problem-working-with-the-operator/#findComment-1150236 Share on other sites More sharing options...
solon Posted December 22, 2010 Share Posted December 22, 2010 By the way why do you need to check the variable $Name and not the $_POST['name']? is there a reason for that? Quote Link to comment https://forums.phpfreaks.com/topic/222367-help-php-generating-weird-problem-working-with-the-operator/#findComment-1150237 Share on other sites More sharing options...
spaceman12 Posted December 22, 2010 Author Share Posted December 22, 2010 I prefer to use $Name to $_POST['Name'] because it is less troublesome when inserting the data to the database. Also, the check is focused on $_POST and it has been declared on top of my code that $Name=$_POST['Name']. I can drop down the tag $Name off from my script should the ISSET has its functions started to impact on $_POST if that is what triggered to cause UNKNOWN errors. However, as you now see that both the cases does failed as in my case. :'( Quote Link to comment https://forums.phpfreaks.com/topic/222367-help-php-generating-weird-problem-working-with-the-operator/#findComment-1150239 Share on other sites More sharing options...
solon Posted December 22, 2010 Share Posted December 22, 2010 well what if you do the check on $_POST['name'] and if the statement is not empty set $Name = $_POST['name'] ? like: if(!isset($_POST['name'])) { //redirect here } // if it is set $Name = $_POST'name']; Quote Link to comment https://forums.phpfreaks.com/topic/222367-help-php-generating-weird-problem-working-with-the-operator/#findComment-1150244 Share on other sites More sharing options...
spaceman12 Posted December 22, 2010 Author Share Posted December 22, 2010 CONCLUSION - !ISSET dont recognize my $_POST['Name'] and always return some values even if contained nothing within it. <?php if(!isset($_POST['Name'])) { echo "no values set"; } else echo $_POST['Name']; ?> This is obvious from the code above. When you enter some info in the field "Name", you always got to see it printed when the code is executed. However, When nothing is filled in and the submit button is clicked, inspite of printing it back the "NO VALUES SET", you always got to see a WHITE BLANK PAGE which violates the !() operator function and this imminently gives us the fact that the $_POST is set with atleast some values even if it is a WHITE SPACE. Quote Link to comment https://forums.phpfreaks.com/topic/222367-help-php-generating-weird-problem-working-with-the-operator/#findComment-1150248 Share on other sites More sharing options...
solon Posted December 22, 2010 Share Posted December 22, 2010 no... well at least it shouldn't. When the $_POST variable is empty it means it was not set so !isset($_POST) will work! and yes white space would probably set the variable. Quote Link to comment https://forums.phpfreaks.com/topic/222367-help-php-generating-weird-problem-working-with-the-operator/#findComment-1150250 Share on other sites More sharing options...
spaceman12 Posted December 22, 2010 Author Share Posted December 22, 2010 But what it wonder me most over of all the above is- **the script worked quite fine before the alteration( putting exit; at the end of each if() function.) **After the alteration, !() operator lost out its significant function **EXIT; dropped off from the script and restore back to what it was before. **! operator lose out its function forever PROOF? if($Password != $Con_Password) { some code } The above code failed to return the values it actually should; Quote Link to comment https://forums.phpfreaks.com/topic/222367-help-php-generating-weird-problem-working-with-the-operator/#findComment-1150252 Share on other sites More sharing options...
solon Posted December 22, 2010 Share Posted December 22, 2010 could you post the complete code? cause this does not seem to be a problem on the operators Quote Link to comment https://forums.phpfreaks.com/topic/222367-help-php-generating-weird-problem-working-with-the-operator/#findComment-1150256 Share on other sites More sharing options...
spaceman12 Posted December 22, 2010 Author Share Posted December 22, 2010 <?php $IP=$_SERVER['REMOTE_ADDR']; $Date=date('d/m/Y'); $proID=$_GET['proID']; $ref=$_GET['ref']; $Name=$_POST['Name']; $Email=$_POST['Email']; $Country=$_POST['Country']; $Username=$_POST['Username']; $Password=$_POST['Password']; $Con_Password=$_POST['Con_Password']; if(!isset($Name)) { header ('Location: reenter.php'); exit(); } if(!isset($Email)) { header ('Location: reenter.php'); exit(); } if(!isset($Country)) { header ('Location: reenter.php'); exit(); } if(!isset($Username)) { header ('Location: reenter.php'); exit(); } if(!isset($Password)) { header ('Location: reenter.php'); exit(); } if($Password != $Con_Password) { header ('Location : reenter.php'); exit(); } $conN = mysql_connect("localhost", "root", ""); if(!$conN) { die('Could Not Connect'.mysql_error()); } mysql_select_db("freebie_allusers", $conN); $locateE="SELECT Email FROM user_info WHERE Email='".$Email."'"; $fetchE=mysql_query($locateE); $resultE=mysql_num_rows($fetchE); if ($resultE>0) { header ( 'Location: reenter.php'); exit(); } $locateU="SELECT Username FROM user_info WHERE Username='".$Username."'"; $fetchU=mysql_query($locateU); $resultU=mysql_num_rows($fetchU); if ($resultU>0) { header ( 'Location: reenter.php'); exit(); } $UIN=mt_rand(1,3); $locateUIN="SELECT UIN FROM user_info WHERE UIN='".$UIN."'"; $fetchUIN=mysql_query($locateUIN); $resultUIN=mysql_num_rows($fetchUIN); if ($resultUIN>0) { $UIN=mt_rand(5,7); $locateUIN="SELECT UIN FROM referral_system WHERE UIN='".$UIN."'"; $fetchUIN = mysql_query($locateUIN); if($fetchUIN=1) { $uinField="ALTER TABLE `referral_system` ADD `".$UIN."` varchar(10) NOT NULL, ADD `Date".$UIN."` varchar(10) NOT NULL"; $createField=mysql_query($uinField); if($createField=1) { if(isset($ref)) { $userRef="INSERT INTO referral_system(`$_GET[ref]`, `Date".$_GET[ref]."`) VALUES('$UIN', '$Date')"; mysql_query($userRef); } else { mysql_query($uinField); if(isset($ref)) { $userRef="INSERT INTO referral_system(`$_GET[ref]`, `Date".$_GET[ref]."`) VALUES('$UIN', '$Date')"; mysql_query($userRef); } } $userInfo="INSERT INTO user_info(Name, Email, Country, Username, Password, UIN, IP, Date) VALUES('".$Name."', '".$Email."', '".$Country."', '".$Username."', '".$Password."', '".$UIN."', '".$IP."', '".$Date."')"; mysql_query($userInfo); echo "INSERTION SUCCESS"; } } } else echo "MORE CODE TO BE INSERTED"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/222367-help-php-generating-weird-problem-working-with-the-operator/#findComment-1150258 Share on other sites More sharing options...
solon Posted December 22, 2010 Share Posted December 22, 2010 your code seems fine. i dont know what the problem might be! If someone else is watching this thread and has an idea... but if it works with $_POST i think you should do it that way Quote Link to comment https://forums.phpfreaks.com/topic/222367-help-php-generating-weird-problem-working-with-the-operator/#findComment-1150271 Share on other sites More sharing options...
spaceman12 Posted December 22, 2010 Author Share Posted December 22, 2010 OMG! I clear and flush out all my cookies on my browser and now it seems to be working good again... whats going on around?......lol Quote Link to comment https://forums.phpfreaks.com/topic/222367-help-php-generating-weird-problem-working-with-the-operator/#findComment-1150287 Share on other sites More sharing options...
spaceman12 Posted December 22, 2010 Author Share Posted December 22, 2010 in one way, !ISSET() totally depends on cookies stored on your browser. It doesnt return you the right values after multiple execution of the ISSET function. empty() is much more reliable.... Anyway thanx for the help SOLON Quote Link to comment https://forums.phpfreaks.com/topic/222367-help-php-generating-weird-problem-working-with-the-operator/#findComment-1150292 Share on other sites More sharing options...
solon Posted December 22, 2010 Share Posted December 22, 2010 you are welcome. At least we learned something new ! Quote Link to comment https://forums.phpfreaks.com/topic/222367-help-php-generating-weird-problem-working-with-the-operator/#findComment-1150295 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.