• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 51
  • Last Modified:

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
0
Richard Korts
Asked:
Richard Korts
  • 3
  • 3
  • 2
  • +1
2 Solutions
 
Chris StanyonCommented:
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 StanyonCommented:
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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
Richard KortsAuthor 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
 
Richard KortsAuthor 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 KortsAuthor 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now