Jump to content

HELP- PHP generating weird problem working with the Operator


spaceman12

Recommended Posts

 

 

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))

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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'];
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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. :D

Link to comment
Share on other sites

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.  :'(

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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



Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.