tags:

views:

185

answers:

5

Hi all - Frustrated php novice here...

I'm trying to pass a "type" value of either billto or shipto from ab.php to abp.php.

ab.php snippet:

<?php
echo '<a href="' . tep_href_link(FILENAME_ABP, 'edit=' . $bill_address['address_book_id'] . '&type=billto', 'SSL') . '">' . 
  tep_image_button('small_edit.gif', SMALL_IMAGE_BUTTON_EDIT) .
'</a>';
?>

This does add the &type=billto to the end of the url. It looks like this: www.mydomain.com/abp.php?edit=408&type=billto&id=4a6524d

abp.php snippet:

if ($HTTP_GET_VARS['type'] == 'billto') {
  then it does a db update...

The if returns false though (from what I can tell) because the update is not performed.

I've also tried $_GET instead of $HTTP_GET_VARS.

Because the code in abp.php isn't executed until after the user clicks a button, I can't use echos to check the value, but I can see the type in the url, so I'm not sure why it's not executing.

Could really use some direction... whether it's what I need to change, or even just suggestions on how to troubleshoot it further. I'm in the middle of a huge learning curve right now. Thanks!!!

edit: Sorry, I just realized I left out that after the db update the user goes back to ab.php. So the whole workflow is this:

User goes to ab.php. User clicks link to go to abp.php. User changes data on abp.php. User clicks button on abp.php. Update to db is executed and user is sent back to ab.php.

+3  A: 

Because the code in abp.php isn't executed until after the user clicks a button, I can't use echos to check the value
Why not?

echo '<pre>Debug: $_GET=', htmlspecialchars(var_export($_GET, true)), "</pre>\n";
echo '<pre>Debug: billto===$_GET[type] = ', 'billto'===$_GET['type'] ? 'true':'false', "</pre>\n";
if ( 'billto'===$_GET['type'] ) {
  ...

edit: You might also be interested in netbeans and its php module:

"Debug PHP code using Xdebug: You can inspect local variables, set watches, set breakpoints, and evaluate code live. Navigate to declarations, types and files using Go To shortcuts and hypertext links."

VolkerK
Debugging PHP is a necessary skill. Dumping your variables on screen is a big part of that. I used NetBeans with XDebug for months before I realized I could actually watch the variables -- yes, go ahead and laugh! -- but just being able to step through the code seemed priceless. So +1 for THAT tip also.
Smandoli
Thanks so much for the quick reply and the link. I'm downloading netbeans now - it looks like exactly what I need to help me debug faster. I guess instead of saying "I can't use echos..." I should have said "I don't know how to get echos to display when the code is executed after a button is clicked..." Thanks again!
FrustratedPHPnovice
You'll have to change your user name before you know it!
Smandoli
+1  A: 

try something like this

if ($_GET['type'] == 'billto') {
  die("got to here, type must == billto");

this will prove that your if statement is working or not, it may be that the update part is not working

bumperbox
Thanks! That proved the if is false - it didn't die... So now the question is why is it false when it's displayed in the url?
FrustratedPHPnovice
see the var_dump suggestion from @timmow, that will show if the values you expect are stored in the $_GET variable. failing that, i notice you have SSL in the original code, can you try it on a plain http connection and see if that makes any difference
bumperbox
+1  A: 

Before the if statement - try

var_dump($_GET);

And make sure the 'billto' is contained within the $_GET array. Of course, if you have got the debuger setup, you should be able to watch the value of the $_GET array

timmow
Thanks! Is there a way to redirect var_dump output? Earlier I left out that after the db update the user goes back to ab.php. So the whole workflow is this: User goes to ab.php. User clicks link to go to abp.php. User changes data on abp.php. User clicks button on abp.php. Update to db is executed and user is sent back to ab.php. So I can't see the output on abp.php because the page is immediately redirected back to ab.php. On "make sure the 'billto' is contained within the $_GET array", just to be sure I've done this correctly, can you elaborate?Thanks so much for all the help!
FrustratedPHPnovice
A: 

or try:

var_dump($_REQUEST);
inakiabt
A: 

Check the URL of the second page, is it in the correct form? From the code snippet you post, I don't know if there would be a ? after the question mark. Also try to disable the redirect to see if your code is working as it should.

One other thing is you may want to put the new url in a variable first, then put that into the link HTML. It's less efficient, but makes the code easier to read and debug.

Try turning on error reporting, place this at the start of your php script

error_reporting ( E_ALL | E_STRICT)

PHP is very tolerant of typos and accessing subscripts in an array that does not exist; by enforcing strict and reporting all errors you would be able to catch those cases.

If you can't see the output, try this:

function log_error($no,$msg,$file,$line)
{

    $errorMessage = "Error no $no: $msg in $file at line number $line";

    file_put_contents("errors_paypal.txt",$errorMessage."\n\n",FILE_APPEND);    
}

set_error_handler('log_error');

You may have to set some file permissions for the log file to be written to.

Of course, you can get Netbeans and its debugging module too.

Extrakun
FrustratedPHPnovice
You may get it to work via. session, but I would urge you to find out why the original method is not working, as a learning experience.
Extrakun