Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    May 2008
    Posts
    119
    Thanks
    13
    Thanked 0 Times in 0 Posts

    PHP script not working - what is going wrong?

    Hi,

    I have the following bit of PHP that is not working. I am basically trying to put together a menu structure:

    Code:
    <?php
    	$sql = "SELECT * FROM PCNET_$filename WHERE page_type='TOP_PAGE' AND live='checked' AND page_order!='x' ORDER BY parent_code, ABS(page_order), title";
    	$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
    	while ($row = mysql_fetch_assoc($sql_result)) {
    		echo '<dt><a href="'.($row["link"]).'?id='.($row["id"]).'">'.($row["menu_title"]).'</a></dt>';
    			if ($row["parent_live"]=='checked') {
    				include ('subgridmenu.php?parent_code=';
    				echo	($row["id"])'');
    			};
    		};
    ?>
    It shows all the pages in the menu list OK, but will not display anything in the subgridmenu.php file, which is as follows:

    Code:
    <?php
    	$sql = "SELECT * FROM PCNET_$filename WHERE page_type='SUB_PAGE' AND live='checked' AND page_order!='x' ORDER BY ABS(page_order), title";
    	$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
    	while ($row = mysql_fetch_assoc($sql_result)) {
    		echo '<dd><a href="'.($row["link"]).'?id='.($row["id"]).'">'.($row["menu_title"]).'</a></dd>';
    		}
    ?>
    Can anyone give me any pointers as to why?

    Thanks,
    Neil

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,283
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    Have you tried running the second subgrid query through phpmyadmin to check that it runs? I've never trusted the or die() method, it's a bit flawed and doesn't always work.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You can't do this:
    PHP Code:
                    include ('subgridmenu.php?parent_code=';
                    echo    (
    $row["id"])''); 
    querystrings are HTTP, not FILE protocol based. You can assign $parent_code prior to the include of the subgridmenu.php, or even $_GET['parent_code'].
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    howard-moore (02-24-2013)

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,038
    Thanks
    23
    Thanked 589 Times in 588 Posts
    In top php this line
    PHP Code:
    include ('subgridmenu.php?parent_code='
    is missing a closing parenthese.
    PHP Code:
    include ('subgridmenu.php?parent_code='); 
    and shouldn't it have the parent_code variable?

    This line
    PHP Code:
    echo    ($row["id"])''); 
    At first I'd say it has an extra parenthese, but then I've never seen parentheses like that in an echo.

    So I'm guessing:
    PHP Code:
    if ($row["parent_live"]=='checked') {
        include (
    'subgridmenu.php?parent_code='.$row["id"]);
        
    //echo ($row["id"]).'';
    }; 

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,283
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    Quote Originally Posted by sunfighter View Post
    So I'm guessing:
    PHP Code:
    if ($row["parent_live"]=='checked') {
        include (
    'subgridmenu.php?parent_code='.$row["id"]);
        
    //echo ($row["id"]).'';
    }; 
    As fou says, you can't use parameters on file system calls, only urls. Why? With the file system there is no webserver to deal with the parameters.

    @Fou: Good catch.. I missed another glaringly obvious issue

    I think I'm going to take a week or two off... I'm clearly loosing the plot
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #6
    Regular Coder
    Join Date
    May 2008
    Posts
    119
    Thanks
    13
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    As fou says, you can't use parameters on file system calls, only urls. Why? With the file system there is no webserver to deal with the parameters.

    @Fou: Good catch.. I missed another glaringly obvious issue

    I think I'm going to take a week or two off... I'm clearly loosing the plot
    Thanks - that was exactly the issue!

    Really appreciate your help.

    Neil

  • #7
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,283
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    It's Fou you need to thank - go up and click his big green "Thank User for this post" button
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •