Solved

PHP script dying...why?

Posted on 2007-04-11
6
257 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now