3
votes

I don't know what to do, my index page doesn't work... I mean it working perfectly before I add function slider that already connect to database... What must I do?

An uncaught Exception was encountered

Type: ParseError

Message: syntax error, unexpected 'endforeach' (T_ENDFOREACH), expecting end of file

Filename: C:\xampp\htdocs\eat\application\views\front\index.php

Line Number: 96

Backtrace:

File: C:\xampp\htdocs\eat\application\controllers\index.php Line: 15 Function: view

File: C:\xampp\htdocs\eat\index.php Line: 315 Function: require_once

view: index.php

<!--- Carousel --> 
<div id="myCarousel" class="carousel slide" data-ride="carousel">
                <div class="carousel-inner">
                    <?php foreach ($slider as $slider) ?>
                    <div class="item-active">
                        <img src="<?php echo base_url('upload/banner/'.$banner->image)?>">
                        <div class="carousel-caption">
                            <h3><?=$slider->name?></h3>
                            <p><?=$slider->description?></p>
                        </div>
                    </div>
                    <div class="item">
                        <img src="<?php echo base_url('upload/banner/'.$banner->image)?>">
                        <div class="carousel-caption">
                            <h3><?=$slider->name?></h3>
                            <p><?=$slider->dekripsi?></p>
                        </div>
                    </div>
                </div>
                <a class="left carousel-control" href="#myCarousel" data-slide="prev">
                    <span class="glyphicon glyphicon-chevron-left"></span>
                    <span class="sr-only"> previous</span>
                </a>
                <a class="right carousel-control" href="=#myCarousel" data-slide="next">
                    <span class="glyphicon glyphicon-chevron-right"></span>
                    <span class="sr-only"> next </span> 
                </a>
            </div>
            <?php endforeach; ?> 

controller: index.php

<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Index extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->model("Indexweb_model");
        $this->load->library('form_validation');
    }

    public function index()
    {
        $data["slider"] = $this->Indexweb_model->getAll();
        $this->load->view("front/index", $data);
    }
}

model: Indexweb_model.php

<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Indexweb_model extends CI_Model
{
    private $_table = "slider";

    public $id_slider;
    public $name;
    public $deskripsi;
    public $image;

    public function rules()
    {
        return [
            ['field' => 'name',
            'label' => 'Name',
            'rules' => 'required']
        ];
    }

    public function getAll()
    {
        return $this->db->get($this->_table)->result();
    }

    public function getById($id)
    {
        return $this->db->get_where($this->_table, ["id_slider" => $id])->row();
    }

    public function save()
    {
        $post = $this->input->post();
//      $this->id_slider = uniqid();
        $this->name = $post["name"];
        $this->deskripsi = $post["deskripsi"];
        $this->image = $this->_uploadImage();
        $this->db->insert($this->_table, $this);
    }

    public function update()
    {
        $post = $this->input->post();
        $this->id_slider = $post["id"];
        $this->name = $post["name"];
        $this->deskripsi = $post["deskripsi"];
        if (!empty($_FILES["image"]["name"])) {
            $this->image = $this->_uploadImage();
        } else {
            $this->image = $post["old_image"];
        }
        $this->db->update($this->_table, $this, array('id_slider' => $post['id']));
    }

    public function delete($id)
    {
        $this->_deleteImage($id);
        return $this->db->delete($this->_table, array("id_slider" => $id));
    }

    private function _uploadImage()
    {
        $config['upload_path']          = './upload/slider/';
        $config['allowed_types']        = 'gif|jpg|png|jpeg';
        $config['upload_max_filesize']  = '100000M';
        $config['post_max_size']        = '100000M';
        $config['file_name']            = basename($_FILES["image"]["name"]);
        $config['overwrite']            = true;

        $this->load->library('upload', $config);

        if ($this->upload->do_upload('image')) {
            return $this->upload->data("file_name");
        }
    }

    private function _deleteImage($id)
    {
        $slider = $this->getById($id);
        if ($slider->image != "default.jpg") {
            $filename = explode(".", $slider->image)[0];
            return array_map('unlink', glob(FCPATH."upload/slider/$filename.*"));
        }
    }

}
2
A 500 error is a generic error message and covers pretty much every single thing that can go wrong with a script. Check your server error logs to find out the exact error message.aynber
4xx errors - Users fault. 5xx errors - YOUR fault. Check your php error_logdelboy1978uk
Yes, lotw could be wrong. Get in the habit of adding the ; at the end of each line. It could be as simple as that. or defined('basepath') ? no 'if'?Gavin Simpson
i already can access it but somehow my slider is not workingKuroda Ayumu

2 Answers

1
votes

Your syntax is wrong. You were missing a colon and your endforeach was in the wrong place.

Try this instead:

<!--- Carousel --> 
<div id="myCarousel" class="carousel slide" data-ride="carousel">
    <div class="carousel-inner">
        <?php foreach ($slider as $slider): ?>
        <div class="item-active">
            <img src="<?php echo base_url('upload/banner/'.$banner->image)?>">
            <div class="carousel-caption">
                <h3><?=$slider->name?></h3>
                <p><?=$slider->description?></p>
            </div>
        </div>
        <div class="item">
            <img src="<?php echo base_url('upload/banner/'.$banner->image)?>">
            <div class="carousel-caption">
                <h3><?=$slider->name?></h3>
                <p><?=$slider->dekripsi?></p>
            </div>
        </div>
        <?php endforeach; ?> 
    </div>
    <a class="left carousel-control" href="#myCarousel" data-slide="prev">
        <span class="glyphicon glyphicon-chevron-left"></span>
        <span class="sr-only"> previous</span>
    </a>
    <a class="right carousel-control" href="=#myCarousel" data-slide="next">
        <span class="glyphicon glyphicon-chevron-right"></span>
        <span class="sr-only"> next </span> 
    </a>
</div>
0
votes

500 errors are non-specific and should generally direct you to check your PHP log files for more information. Make sure that you do have logging enabled and a file specified in your php.ini file. You may want to check both there as well as your webserver logs.