Jump to content

Domagoj

New Members
  • Posts

    4
  • Joined

  • Last visited

Posts posted by Domagoj

  1. Hello im getting this error:

    Fatal error: Uncaught Error: Call to a member function prepare() on null in D:\wamp\www\shop\app\models\m_categories.php on line 35

    here is my code for m_categories.php

    <?php
    /*
        Categories
        Handles all tasks related to retrieving and displaying categories
    */
    
    class Categories
    {
        private $Database;
        private $db_table='categories';
    
        function __construct()
        {
            global $Database;
            $this->Database=$Database;
        }
    
        /*
            Settting/Getting categories from database
        */
    
        /**
         * Return an array with category information
         * 
         * @access public
         * @param   int(optional)
         * @return array
         */
        public function get_categories($id=NULL)
        {
            $data=array();
            if($id != NULL)
            {
                // get specific category
                if($stmt=$this->Database->prepare("SELECT id, name FROM" . $this->db_table . " WHERE id=? LIMIT 1"))
                {
                    $stmt->bind_param("i", $id);
                    $stmt->execute();
                    $stmt->store_result();
    
                    $stmt->bind_result($cat_id,$cat_name);
                    $stmt->fetch();
    
                    if($stmt->num_rows > 0)
                    {
                        $data=array('id'=>$cat_id, 'name'=>$cat_name);
                    }
                    $stmt->close();
    
                }
            }
            else
            {
                // get all categories
                if($result=$this->Database->query("SELECT * FROM" . $this->db_table . "ORDER BY name"))
                {
                    if($result->num_rows>0)
                    {
                        while($row=$result->fetch_array())
                        {
                            $data[]=array('id'=>$row['id'], 'name'=>$row['name']);
                        }
                    }
                }
            }
            return $data;
        }
    
    }
    
    ?>

    and init.php

    <?php
    /*
    
        INIT
        Basic configuration settings
    
    */
    
    // connect to database
    $server='localhost';
    $user='root';
    $pass='';
    $db='shop';
    
    $database=new mysqli($server,$user,$pass,$db);
    
    // error reporting
    mysqli_report(MYSQLI_REPORT_ERROR);
    ini_set('display_errors', 1);
    
    // setup constants
    define('SITE_NAME', 'Online Store');
    define('SITE_PATH','http://shop/');
    define('IMAGE_PATH','http://shop/resources/images/');
    
    // include objects
    include('app/models/m_template.php');
    include('app/models/m_categories.php');
    
    // create objects
    
    $template= new Template();
    $categories= new Categories();
    
    
    session_start();

    and index.php:

    <?php
    
    include('app/init.php');
    
    echo "<pre>";
    print_r($categories->get_categories(3));
    echo "</pre>";
    
    /*$template->set_data('header','hello');
    $template->set_alert('alert!');
    $template->load('app/views/v_public_home.php', 'Welcome!');*/
     ?>
    

    Thank you in advance.

  2. Sorry for late reply, I didn't manage to resolve this. I've took a break cause no one seemed to reply and I simply could not work it out and I took another course. Would love to finish this one though.

  3. Hello,

    i know that iwd tutorials are few years old but im going through them now and in build cms tutorial i can't get colorbox to work. When i press login nothing happens.

    <link rel="stylesheet" type="text/css" href="<?php echo APP_RESOURCES;?>css/fp_style.css" media="screen"/>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script type="text/javascript">$.noConflict();</script>
    
    <script type="text/javascript" src="<?php echo APP_RESOURCES;?>javascript/colorbox/colorbox.js"></script>
    <link rel="stylesheet" type="text/css" href="<?php echo APP_RESOURCES;?>javascript/colorbox/colorbox.css" media="screen"/>
    
    <script type="text/javascript">
    	jQuery(document).ready(function($){
    	$.colorbox({
    		transition:'fade',
    		initialWidth:'50px',
    		initialHeight:'50px',
    		scrolling:false,
    		opacity:.6,
    		href:'<?php echo SITE_PATH; ?>app/login.php'
    	});
    });
    </script>

    I don't get any errors just redirected to http://localhost/CMS/?Login

×
×
  • Create New...