#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    15
    Rep Power
    0

    Lynda essential training dvd error


    Hello, i have using Lynda's essential training DVD to study PHP and i have a small issue on lesson 12 section 11. I have a script that is suposed to echo the number of the page or the number of the subject that i'm currently at. I will post my script and then tell you the error that i get:

    PHP Code:
    <?php require("includes/connection.php"); ?> 
    <?php require("includes/functions.php"); ?>
    <?php
        
    if(isset($_GET['subj'])){
            
    $sel_subj $_GET['subj'];
            
    $sel_page "";
            } elseif (isset(
    $_GET['page'])){
                
    $sel_subj "";
                
    $sel_page $_GET['page'];
            } else {
                
    $sel_page "";
                
    $sel_subj "";
                echo 
    "No values!";
            }
    ?>
    <?php 
    include("includes/header.php"); ?>
            <table id="structure">
                <tr>
                    <td id="navigation">
                    <ul class="subjects">
                    <?php
                    
                    
                    $subject_set 
    get_all_subjects();
                    while(
    $subjects mysql_fetch_array($subject_set)){
                    echo 
    "<li class = \"selected\"><a href = \"content.php?subj=" 
                    
    urlencode($subjects["id"]) . "\">{$subjects["menu_name"]}</a></li>";
                    
                            
                    
                    
    $page_set get_pages_for_subject($subjects["id"]);
                    echo 
    "<ul class = \"pages\">";
                    while(
    $pages mysql_fetch_array($page_set)){
                    echo 
    "<li><a href = \"content.php\page=" 
                    
    urlencode($pages["id"]) . "\">{$pages["menu_name"]}</a></li>";
                    }
                                                   
                    echo 
    "</ul>";
                    }               
                     
    ?>   
                     </ul>
                    </td>
                    <td id="page">
                        <h2>Content Area</h2>
                        <p>Welcome to staff area.</p>
                        <?php echo $sel_subj?> <br />
                        <?php echo $sel_page?> <br />
                        <ul>
                            <li><a href="content.php">Manage Website Content</a></li>
                            <li><a href="new_user.php">Add Staff User</a></li>
                            <li><a href="logout.php">Logout</a></li>
                        </ul>
                    </td>
                </tr>
        </table>
    <?php require("includes/footer.php"); ?>
    OK, sorry for no comments but i'm a begginer. OK, so my problem is that the code actualy works. But and there is a but, it only works one time for submenu's(page's). So if i click on a page i get the number of that page. But it only happend's once. The second time it's not working. It's echo-ing "No values". I don't get this error for subjects. And i tried with the original Lynda code and it's the same thing. I tried to use require instead of require_once but it's still not working. Anyone got any ideea's? Thank you very much!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,571
    Rep Power
    595
    1) You don't need all those extra PHP tags. It makes for somewhat confusing code.
    2) Since you don't show your form that submits the page, it is very difficult to determine why $_GET is not set (which obviously is why you are getting that result).
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Posts
    3,016
    Rep Power
    376
    1. what do you mean by "second time"?
    2. make sure that second time you still have a query parameter in the URL string
    3. if you really are using a form like the above poster said, you have something like:
    <form action=thepage.php but no parameter, you need something likel
    <form action=thepage.php?subjectid=122

    can you give a link to the page maybe?
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    15
    Rep Power
    0

    Solved


    It was this line's of code that had a syntax error:

    PHP Code:
    echo "<li><a href = \"content.php\page="  
                    
    urlencode($pages["id"]) . "\">{$pages["menu_name"]}</a></li>"
                    } 

    the correct way to write it is:

    PHP Code:
    echo "<li><a href=\"content.php?page=" urlencode($pages["id"]) .
                        
    "\">{$pages["menu_name"]}</a></li>"

    Thank you for your support!

IMN logo majestic logo threadwatch logo seochat tools logo