Imposible php behavior

see this code:
$yd = 293;
// check box for assemply type
if ($_SESSION['asstyp'] == "RP" || $_SESSION['asstyp'] == "RPD") {
	$yd = 273;
}
$pdf->SetFont('Arial','B',10);
if ($_SESSION['asstyp'] == "RP") {
		$xd = 218;
}
if ($_SESSION['asstyp'] == "RPD") {
		$xd = 295;
}
if ($_SESSION['asstyp'] == "DCV") {
		$xd = 210;
}
if ($_SESSION['asstyp'] == "DCD") {
		$xd = 225;
}
//echo "yd = " . $yd . "<br>";
if ($_SESSION['asstyp'] != "PVB" && $_SESSION['asstyp'] != "SVB") {
	$pdf->SetXY($xd,$yd);	
	$pdf->Cell(20,20,"X",0,0);
}	

Open in new window


When the value of $_SESSION['asstyp'] = "RP", it works fine.

In the case of "RPD", it ignores the $xp setting.

In all the other cases, it sets $yp to something like 333 (I can't tell exactly) but does the $xp about right.

I had a php switch; when all this started I changed to the bunch of if's because I was sure the switch was not working. The switch gave the EXACT same result.

I realize it has to be something obvious that I cannot see.

If you know fpdf that would help. I am trying to overlay data on an existing image background.

Thank you
Richard KortsBusiness Owner / Chief DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
Can't see anything obvious Richard, but I guess we're only seeing part of your code. May be worth trying some simple tests and dumping your data to see what's going on.

I'm assuming you are called session_start() right at the beginning of your code.

For debugging purposes remove or comment out all the PDF stuff so you can concentrate on just the variables. Here's a quick run down that I teste as working:

<?php
// Start the Session
session_start();

// Visualise the SESSION
var_dump($_SESSION);

// Set some defaults
$yd = 293;
$xd = 0;

// Switch the session variable
switch ($_SESSION['asstyp']):
    case 'RP':
        $yd = 273;
        $xd = 218;    
        break;

    case 'RPD':
        $yd = 273;
        $xd = 295;    
        break;

    case 'DCV':
        $xd = 210;    
        break;

    case 'DCD':
        $xd = 225;    
        break;

endswitch;

// Visualise the variables
var_dump($xd, $yd);

Open in new window

0
Chris StanyonWebDevCommented:
Just another quick thought. Double check the variable names - in your code, you have variables called $xd and $yd, but in your question you refer to them as $xp and $yp - not sure if that's just a typo in your question!
0
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
I believe the problem has to do with scoping.

Try placing $xd = 0; just below $yd = 293; + see if your problem magically resolves.

You're setting $xd in local scopes + then trying to reference it at a higher scope, at which point... it's gone out of scope + lost it's value.
0
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
The $xp, etc., are typos (I hope). Actually, I hope not, that would solve it.

I am not at my main machine, I will try the suggestions.

Thank you,

Richard
0
Julian HansenCommented:
Just for interest here is your exact code supplemented with some dummy code to make it work
<?php
/* START SUPPLEMENTARY */
class PDF
{
  function SetFont($a, $b, $c) {}
  function SetXY($x, $y) {
    echo "SetXY: x = {$x} and y = {$y}<br>";
  }
  function Cell($a,$b,$c,$d,$e){}
}
session_start();
$pdf = new PDF();
$_SESSION['asstyp'] = 'RP';

/* END SUPPLEMENTARY */

$yd = 293;
// check box for assemply type
if ($_SESSION['asstyp'] == "RP" || $_SESSION['asstyp'] == "RPD") {
  $yd = 273;
}
$pdf->SetFont('Arial','B',10);
if ($_SESSION['asstyp'] == "RP") {
  $xd = 218;
}
if ($_SESSION['asstyp'] == "RPD") {
  $xd = 295;
}
if ($_SESSION['asstyp'] == "DCV") {
  $xd = 210;
}
if ($_SESSION['asstyp'] == "DCD") {
  $xd = 225;
}
echo "yd = " . $yd . "<br>";
if ($_SESSION['asstyp'] != "PVB" && $_SESSION['asstyp'] != "SVB") {
  $pdf->SetXY($xd,$yd);	
  $pdf->Cell(20,20,"X",0,0);
}

Open in new window

Output
yd = 273
SetXY: x = 218 and y = 273

Open in new window

Change line 13 to RPD
yd = 273
SetXY: x = 295 and y = 273

Open in new window

So logic is fine, code is fine - problem is elsewhere
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
Julian, for whatever reason, it works correctly (vertically, $yd) for RP AND RPD.

Try DCV.

Richard
0
Julian HansenCommented:
Setting $_SESSION['asstyp'] = 'DCV';
Gives
yd = 293
SetXY: x = 210 and y = 293

Open in new window

On the sample code above  - so seems correct.
0
Richard KortsBusiness Owner / Chief DeveloperAuthor Commented:
Egg on my face. I did not realize that, for some reason, Filezilla was NOT completing the upload of the revised php file; I saw it when today I put a bare bones version up, tried to upload & it was NOT uploading.

So I exited Filezilla, restarted it & viola, it all works perfectly.

Thank you for your efforts!!
0
Julian HansenCommented:
I have noticed that with FZ quite a bit recently - and have been caught by the same issue several times. Upload goes straight to failed - no matter what you do - exit and restart is the only recourse.

Anyway glad it is sorted.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.