0

I am trying to create a CMS and have been watching a youtube tutorial on creating one, but the guy runs into a lot of trouble and doesn't really answer questions about errors people have, so I've been having a lot of trouble with it, basically I'm trying to select a table and display the title of the page at the under the banner.

<?php
    function confirm_query($result_set){
        if (!$result_set){
            die("unable to connect");
        }
    }

    function get_info_by_id($information_id){

        global $connection;
        $query = "SELECT * FROM information WHERE id = $information_id LIMIT 1";
        $result_set = mysql_query($query);
        confirm_query($result_set);
        if($info = mysql_fetch_array($result_set)){
            return $info;
        } else {
            return NULL;
        }
    }

    function get_page_by_id($page_id){

        global $connection;
        $query = "SELECT * FROM pages WHERE id = $page_id LIMIT 1";
        $result_set = mysql_query($query);
        confirm_query($result_set);
        if($page = mysql_fetch_array($result_set)){
            return $page;
        } else {
            return NULL;
        }
    }
?>

<?php

    if (isset($_GET['information'])){

        $sel_table1 = get_info_by_id($_GET['information']) or die ("Error executing get_info_by_id");
        $sel_table2 = NULL;
        $table2 = 0;
        $table1 == $sel_table1;

        echo ('IF statment of _GET is running');

    } elseif (isset($_GET['pages'])){

        $table1 = 0;
        $sel_table2 = get_page_by_id($_GET['pages']) or die ("Error executing get_page_by_id");
        $sel_table1 = NULL;
        $table2 == $sel_table2;

        echo ('Elseif statment of _GET is running');

    } else {

        $table1 = 0;
        $sel_table1 = NULL;
        $sel_table2 = NULL;
        $table2 = 0;

        echo ('Else statement of _GET is running');
    }

?>

<?php

    $query = "SELECT * FROM information ORDER BY position ASC" or die ("Error retrieving database");
    $information_set = mysqli_query($connection, $query) or die ("Error retrieving
    information_result");

    while($info = mysqli_fetch_array($information_set)){

        echo "<li ";
        if ($info["id"] == $table1['id']){
        echo "class = \"selected\"";
    }
        echo "><a href=\"content.php?info=" . urlencode($info["id"]) ."\">"
         . $info['menu'] . "</a></li>";


    $query = "SELECT * FROM pages WHERE information_id ={$info["id"]}  ORDER BY position ASC" or die("Error retrieving database");
    $page_set = mysqli_query($connection, $query) or die ("Error retrieving page_result");

    echo "<ul class=\"pages\">";

    while($page = mysqli_fetch_array($page_set)){

        echo "<li ";
        if ($page["id"] == $table2['id']){
        echo "class = \"selected\"";
    }
        echo "><a href=\"content.php?page=" . urlencode($page["id"]) ."\">"
         . $page['menu'] . "</a></li>";


    }

    echo "</ul>";

    }

    ?>

</td>

<td id = 'main'>

<?php
    if(!is_null($sel_table1)) { ?>
    ?>
    <h2><?php echo $sel_table1['menu'] or die ("Unable to display sel_table1"); ?></h2>
    <?php } elseif (!is_null($sel_table2)) { ?>
    <h2><?php echo $sel_table2['menu']  or die ("Unable to display sel_table2"); ?></h2>
    <div class = 'page-content'>

    <?php
        echo $sel_table2['content'];
    ?>
    </div>

<?php } else { ?>
    <h2> Select a menu from our Information table or Page     table</h2>
<?php } ?>

Everytime I run this it runs the Else statement from the first segment of code. Please help

Jitesh Sojitra
  • 3,655
  • 7
  • 27
  • 46
Asa Greer
  • 9
  • 3
  • else statement from first segment, you mean the else { return NULL} ? – Nodir Rashidov Sep 14 '16 at 17:32
  • 1
    by the way unless you're just learning and this is just a practice app, you must make sure to escape mysql strings. i.e., sending $_GET directly to the SQL line is very insecure, google escape strings mysql for more. And also the tutorial you're following may be old, you should switch to mysqli – Nodir Rashidov Sep 14 '16 at 17:34
  • So obviously I'm learning how to make it wrong, does anyone know a tutorial on making a PHP cms? – Asa Greer Sep 14 '16 at 17:57

0 Answers0