My first PHP/mySQL CMS, and I'm stuck, lol :(

Discussion in 'PHP' started by VisionsIC, Oct 9, 2013.

  1. VisionsIC

    VisionsIC New Member

    Joined:
    Oct 9, 2013
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi fellow coders,

    I'm a noob to PHP/mySQL and I'm enjoying it, but I'm stuck... I'm in the process of developing my first database driven website. I've created the database, the tables... loaded one table in particular with content in an attempt to pull data from it via PHP. If you go to my website live via the browser, there is a navigation system that seems to work but, it's not loading content from the db table. It's just blank content with a nav system that changes the page in the address bar but blank content. I've provided the code along with a image shot of the table in my database I'm trying to GET the data from. The db table i'm getting from is called vls_pages. It is also the table featured in the image. I'm hoping someone can point me to getting this to function correctly. Thank you everyone :)

    index.php CODE:
    -----------------------------------------------------------------------------------------------------------------------
    Code:
    <?php
    
    // Load Setup document:
    
    include
    
    ('_config/setup.php');
    
    ?>
    
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="utf-8">
    <title><?php echo $page_title; ?></title>
    
    <link rel="stylesheet" type="text/css" href="_css/styles.css">
    
    </head>
    
    <body>
    
        <div class="wrap_overall">
        
            
        
            <div class="nav_main">
                <?php include('_template/nav_main.php'); ?>
            </div>
           
            <div class="body_header">
                <?php get_page_name($dbc, $pg); ?>
            </div>   
            
            <div class="content">
                <?php get_page_body($dbc, $pg); ?>    
            </div>
        
            <div class="footer">
                <?php include('_template/footer.php'); ?>
            </div>
            
        </div>
    
    </body>
    
    </html>
    -----------------------------------------------------------------------------------------------------------------------
    setup.php CODE:
    -----------------------------------------------------------------------------------------------------------------------
    Code:
    <?php
    ## Setup Document
    
    // host(or location of the database), username, password, database name
    
                //Variables for connecting to your database.
                
    	    //These variable values come from your hosting account.
                
    			$hostname = "***************";
                            $username = "***************";
                            $password = "***************";
               
                //Connecting to your database
                
    			$dbc = @mysqli_connect($hostname, $username, $password) OR DIE ("Unable to 
                            connect to database! Please try again later.");
    
                // Check connection
               if (mysqli_connect_errno($dbc))
    {
               echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    			
    		   include('_functions/snippets.php');
               
    		   if ($_GET['pgname'] == '') {
    	        $pg = 'home';
                   }
               
    		   else {
    	        $pg = $_GET['pgname'];
    }
    
                $page_title = get_page_title($dbc, $pg);
    
    ?>
    -----------------------------------------------------------------------------------------------------------------------
    snippets.php CODE:
    -----------------------------------------------------------------------------------------------------------------------
    Code:
    <?php
    
    // Snippets; Functions
    
    function get_page_title ($dbc, $pg) {
    
    	$query = "SELECT pgtitle FROM vls_pages AND pgstatus = 1 LIMIT 1";
        $result = @mysqli_query($dbc, $query);
    	$page = @mysqli_fetch_assoc($result);
    	
    	return $page['pgtitle'];
    	
        @mysqli_close($dbc);
    	
    }
    
    function get_page_name ($dbc, $pg) {
    
    	$query = "SELECT pgname FROM vls_pages WHERE pgname = '$pg' AND pgstatus = 1 LIMIT 1";
        $result = @mysqli_query($dbc, $query);
    	$page = @mysqli_fetch_assoc($result);
    	
    	echo '<h1>'.$page['pgname'].'</h1>';
    	
        @mysqli_close($dbc);
    	
    }
    
    function get_page_body ($dbc, $pg) {
    
    	// the database connection, our query
    
    	$query = "SELECT * FROM vls_pages WHERE pgbody = '$pg' AND pgstatus = 1 LIMIT 1";
    	$result = @mysqli_query($dbc, $query);
    	$page = @mysqli_fetch_assoc($result);
    
    	echo '<div class="content">'.$page['pgbody'].'</div>';
    
        @mysqli_close($dbc);
    		
    }
    
    ?>
    -----------------------------------------------------------------------------------------------------------------------
     

    Attached Files:

    Last edited by a moderator: Oct 10, 2013
  2. c_user

    c_user New Member

    Joined:
    Aug 23, 2009
    Messages:
    86
    Likes Received:
    8
    Trophy Points:
    0
    Occupation:
    Php dev
    Location:
    Bhubaneswar
    use var_dump() to check if the the query is being fetched or not.
    ex :-
    PHP:
    <?php 
    $que           
    $this->db->query"SELECT * FROM `exam`" );
            
    $exam = array( );
            while ( 
    $res $que->fetch_assoc() )
            {
                
    $exam[ ] = $res;
            }
            
    var_dump($exam);               // This will show all the data of the exam. In the similar way try for rest

    exit;
    This will help you in finding the where the problem lies.
    make check point and check your code !
    Good Day !
     
    Last edited: Oct 17, 2013
    shabbir likes this.
  3. c_user

    c_user New Member

    Joined:
    Aug 23, 2009
    Messages:
    86
    Likes Received:
    8
    Trophy Points:
    0
    Occupation:
    Php dev
    Location:
    Bhubaneswar
    After U able to patch the problem ; DONT FORGET to REMOVE var_dump() and exit() .
     
  4. VisionsIC

    VisionsIC New Member

    Joined:
    Oct 9, 2013
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    where in the coding would I place this lil script, after each of my functions on the "snippets.php" page.... before I request the @mysqli_close?
     
  5. c_user

    c_user New Member

    Joined:
    Aug 23, 2009
    Messages:
    86
    Likes Received:
    8
    Trophy Points:
    0
    Occupation:
    Php dev
    Location:
    Bhubaneswar
    @VisionslC U will get the revised code soon ! Sunday my ofc will be off , i will optimize your code ..
    Hope would be helpful .
    Take care.
     
  6. c_user

    c_user New Member

    Joined:
    Aug 23, 2009
    Messages:
    86
    Likes Received:
    8
    Trophy Points:
    0
    Occupation:
    Php dev
    Location:
    Bhubaneswar
    There is a problem in the mysql statement.
    This was your code where the error lies Snippets
    PHP:
    function get_page_title ($dbc$pg) {

        
    $query "SELECT pgtitle FROM vls_pages AND pgstatus = 1 LIMIT 1";
        
    $result = @mysqli_query($dbc$query);
        
    $page = @mysqli_fetch_assoc($result);
        
        return 
    $page['pgtitle'];
        
        @
    mysqli_close($dbc);
        
    }
    Corrected code:-
    PHP:
    function get_page_title ($dbc$pg) {

        
    $query "SELECT pgtitle FROM vls_pages WHERE pgstatus = 1 LIMIT 1";
        
    $result = @mysqli_query($dbc$query);
        
    $page = @mysqli_fetch_assoc($result);
        
        
        
    var_dump($page);
        echo 
    "page title part";
        exit;
        
            
        return 
    $page['pgtitle'];
        
        
        
        
        @
    mysqli_close($dbc);
        
    }
     
    shabbir likes this.
  7. c_user

    c_user New Member

    Joined:
    Aug 23, 2009
    Messages:
    86
    Likes Received:
    8
    Trophy Points:
    0
    Occupation:
    Php dev
    Location:
    Bhubaneswar
    This is how var_dump is used. Remove the var_dump and exit after testing.
    and also u not need to call the db connection each and every time you call the function. .
    try using a framework dude !
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice