0

I had an unexpected end of file error but I checked my code and I didn't find any sign of this error! So can you tell me what may be the cause of this problem! Here is my file's code that contains the error (this is a project done with cakephp):

<?php
     App::uses('AppController', 'Controller');

     class AdminsController extends AppController {

  public function login($id = null) 
{       


    $this->layout='login';


    if ($this->request->is('post')) {

        $user=$this->request->data['Admin']['r'];



        if ($user == 'Administrator')
        {   
            $Admin=$this->request->data['Admin']['login'];
            $mdp=$this->request->data['Admin']['motpasse'];

            $Admins=$this->Admin->find('count',array('conditions'=>array('Admin.login'=>$Admin,'Admin.motpasse'=>$mdp)));

            if ($Admins ==1) 
                {sleep(2);
                    CakeSession::write('admin','admin' );
                    CakeSession::write('nom',$Admin);
                    $this->redirect(array('action' => 'index'));

                }else {?><script type="text/javascript">
                confirm('M.Admin Login ou Mot de passe incorrect');
            </script><?}

        }


        if ($user == 'Commercial')
        {   
            App::Import('Model', 'Commercial'); 

            $Admin=$this->request->data['Admin']['login'];
            $mdp=$this->request->data['Admin']['motpasse'];

            $category = new Commercial(); 
            $categories = $category->find('count',array('conditions'=>array('Commercial.login'=>$Admin,'Commercial.motpasse'=>$mdp))); 

            if ($categories ==1) 
            { 
                CakeSession::write('admin','com' );
                CakeSession::write('nom',$Admin);
                $this->redirect(array('controller' => 'Commercials', 'action' => ''));
            }

        }
    }
}



 public function logout($id = null) 
{    
    $this->Session->destroy();
    $this->redirect(array('action' => 'login'));




}


  public function index() {

$admin=CakeSession::read('admin');
if(($admin<>'admin')&&($admin<>'com'))
    {$this->redirect(array('controller' => 'Admin', 'action' => 'login'));}

if($admin=='com')
    {$this->layout='Commercials';}

$this->Admin->recursive = 0;
$this->set('admins', $this->paginate());
    }


    public function view($id = null) {

$admin=CakeSession::read('admin');
if(($admin<>'admin')&&($admin<>'com'))
    {$this->redirect(array('controller' => 'Admin', 'action' => 'login'));}

if($admin=='com')
    {$this->layout='Commercials';}

if (!$this->Admin->exists($id)) {
    throw new NotFoundException(__('Invalid admin'));
}
$options = array('conditions' => array('Admin.' . $this->Admin->primaryKey => $id));
$this->set('admin', $this->Admin->find('first', $options));
   }


   public function add() {

$admin=CakeSession::read('admin');
if(($admin<>'admin')&&($admin<>'com'))
    {$this->redirect(array('controller' => 'Admin', 'action' => 'login'));}

if($admin=='com')
    {$this->layout='Commercials';}

if ($this->request->is('post')) {
    $this->Admin->create();
    if ($this->Admin->save($this->request->data)) {
        $this->Session->setFlash(__('The admin has been saved'));
        $this->redirect(array('action' => 'index'));
    } else {
        $this->Session->setFlash(__('The admin could not be saved. Please, try again.'));
    }
}
$questionnaires = $this->Admin->Questionnaire->find('list');
$this->set(compact('questionnaires'));
   }


    public function delete($id = null) {

$admin=CakeSession::read('admin');
if(($admin<>'admin')&&($admin<>'com'))
    {$this->redirect(array('controller' => 'Admin', 'action' => 'login'));}

if($admin=='com')
    {$this->layout='Commercials';}

$this->Admin->id = $id;
if (!$this->Admin->exists()) {
    throw new NotFoundException(__('Invalid admin'));
}
$this->request->onlyAllow('post', 'delete');
if ($this->Admin->delete()) {
    $this->Session->setFlash(__('Admin deleted'));
    $this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('Admin was not deleted'));
$this->redirect(array('action' => 'index'));
   }
   }
   ?>

This is the error that shows up:

enter image description here

George Kagan
  • 5,913
  • 8
  • 46
  • 50
  • 1
    If you fix the indentations you will probably be able to figure out what is not closed. – chris85 Nov 13 '16 at 19:24
  • I copied my code on a online phpchecker and 0 issues are found so i think it's a misguiding error ! –  Nov 13 '16 at 19:27

1 Answers1

0

And have a look here:

if ($Admins ==1) 
            {sleep(2);
                CakeSession::write('admin','admin' );
                CakeSession::write('nom',$Admin);
                $this->redirect(array('action' => 'index'));

            }else {?><script type="text/javascript">
            confirm('M.Admin Login ou Mot de passe incorrect');
        </script><? } // look at here
        ?>

that should be:

if ($Admins ==1) 
            {sleep(2);
                CakeSession::write('admin','admin' );
                CakeSession::write('nom',$Admin);
                $this->redirect(array('action' => 'index'));

            }else {?><script type="text/javascript">
            confirm('M.Admin Login ou Mot de passe incorrect');
        </script><?php } // your little mistake was here
       ?>

Did you notice you were missing php there.

Manohar Khadka
  • 2,186
  • 2
  • 18
  • 30
  • I added the missing PHP and another errors are showing up ! a lots of them so I'm asking if I may post my hole project so you can find out what are all these errors about please ?! –  Nov 16 '16 at 19:23