Solved

PHP script dying...why?

Posted on 2007-04-11
6
291 Views
Last Modified: 2012-05-05
I have a function looking like this:

function remove_tree($tid){
    $Q = "DELETE FROM tree WHERE Id = $tid";
    $R = mysql_query($Q);
    $Q2 = "SELECT * FROM tree_member WHERE tree_id = $tid";
    $R2 = mysql_query($Q2);
    while($rec = mysql_fetch_object($R2)){
        echo "deleting indi:".$rec->individual_id;
        del_indi($rec->individual_id, 1);
    }
    echo "OK";
}

As long as I comment out the call to del_indi everything is ok, but when the call is in there the script never reaches the echo "OK".
I have tried with commenting out everything inside the del_indi function which otherwise is working ok when called directly, but still the issue remains, the script will stop executing as long as the call is there.

The del_indi function is now looking like this:

function del_indi($id, $silent) {
    echo "deleting:".$id;
}

I never recive the echo from del_indi.
The MySQL statements is working ok (the correct row in table "tree" is deleted and echo "deleting indi" returns the right id).

PHP Version is 5.1.2
0
Comment
Question by:Blixtsystems
  • 4
6 Comments
 
LVL 24

Accepted Solution

by:
glcummins earned 65 total points
ID: 18889715
>> The del_indi function is now looking "like" this:

Is the function you listed here 'exactly' what is listed in your code, or is it 'like' the one that is actually in use? I notice that the function has a $silent flag, and I wonder if that is coming into play here.
0
 
LVL 4

Author Comment

by:Blixtsystems
ID: 18889782
There used to be code in there, but I stripped it out for testing for now.

I made an even more stripped down version:

      function main(){
            echo "main";
            //test();
            echo "OK";
      }
      function sub(){
            echo "sub";
      }

That will return "mainOK"

However:

      function main(){
            echo "main";
            test();
            echo "OK";
      }
      function sub(){
            echo "sub";
      }

will return only "main"

The functions is inside a class instantiated in engine.php like this:

require_once('classes/engine.class.php');
$engine = new engine();
$engine->main();
0
 
LVL 4

Author Comment

by:Blixtsystems
ID: 18889811
Sorry that should be:

      function main(){
            echo "main";
            sub();
            echo "OK";
      }
      function sub(){
            echo "sub";
      }

Result is the same however
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 4

Author Comment

by:Blixtsystems
ID: 18889897
ok...I figured it was a scope issue of some sort and is used to having the scope of the class accessible inside the function.
But apparently I need a $this->sub()
0
 
LVL 12

Assisted Solution

by:Jeff Darling
Jeff Darling earned 60 total points
ID: 18889899
Try adding a return; to the sub.

like this

function main(){
 echo "main";
 sub();
 echo "OK";
      }

function sub(){
   echo "sub";
   return;
}
0
 
LVL 4

Author Comment

by:Blixtsystems
ID: 18889960
It was simply a scope issue like I explained above.
Since I'm new to this site I'm not sure what to do when I solved the issue myself, so I'll just give you guys the points for your effort.
Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question