1

I made a controller for a web, this controller works between desktop and mobile user if user coming from mobile so it shows another view and if user come from desktop computer so it shows another view for that thing I made a code but when I upload a code on website and try to run it shows error this error:

Parse error: syntax error, unexpected T_ELSE in line 17

Here is my code:

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

class Welcome extends CI_Controller {
    public function index()
    {
        $this->load->library('user_agent');
        $this->load->helper('url');

        if ($this->input->get("lang") =="en")
        {
            if ($this->agent->is_mobile())
            {
                $this->load->view('m_english_signup');
            }
        }
        else
        {
            $this->load->view('d_english_signup');
        }
        else 
            $this->agent->is_mobile()
            {
            $this->load->view('m_arabic_signup');
            }
        else {
            $this->load->view('d_arabic_signup');
        }
    }
}
Soma
  • 857
  • 2
  • 17
  • 32
FormaL
  • 359
  • 2
  • 4
  • 19
  • 1
    if else brackets are not correct.. check.. u have `else{}else{} `which is wrong.. – Roy M J Jan 15 '14 at 08:53
  • There are many else after else – Abhik Chakraborty Jan 15 '14 at 08:55
  • yes i add too many else because total 4 pages of website with multi language for arabic desktop / mobile users , for english mobile / desktop user please suggest how i rectify this code. – FormaL Jan 15 '14 at 08:57
  • i check all brackets in notepad++ it shows opening and closing brackets completed RoymJ – FormaL Jan 15 '14 at 08:58
  • @FormaL: please see my answer, `else{}else{}` is wrong syntax.. `if{}else{}` is right.. – Roy M J Jan 15 '14 at 09:01
  • @RoyMJ [link](http://stackoverflow.com/questions/21201276/codeigniter-email-class-registration-after-submission) will you please suggest. – FormaL Jan 18 '14 at 14:42

8 Answers8

2

try this

class Welcome extends CI_Controller {
    public function index()
    {
        $this->load->library('user_agent');
        $this->load->helper('url');

        if ($this->input->get("lang") =="en"){
            if ($this->agent->is_mobile()) {
              $this->load->view('m_english_signup');
            } else {
                $this->load->view('d_english_signup');
            } 
        } else if($this->agent->is_mobile()) {
            $this->load->view('m_arabic_signup');
        } else {
            $this->load->view('d_arabic_signup');
        }

    }
}
Harish Singh
  • 3,198
  • 5
  • 20
  • 39
1

You again made mistake in placing the code for mobile check. Try this:

<?php

if (!defined('BASEPATH'))
exit('No direct script access allowed');

class Welcome extends CI_Controller {

public function index() {
    $this->load->library('user_agent');
    $this->load->helper('url');

    if ($this->input->get("lang") == "en") {
        if ($this->agent->is_mobile()) {
            $this->load->view('m_english_signup');
        } else {
            $this->load->view('d_english_signup');
        }
    } else {
        if ($this->agent->is_mobile()) {
            $this->load->view('m_arabic_signup');
        } else {
            $this->load->view('d_arabic_signup');
        }
    }
}

}
user2936213
  • 1,041
  • 1
  • 8
  • 19
  • yes i try but u knew it i am new in programming so i mess in code even right now i already face problem in user file but i dont know how to rectify my code from last 7 hours i spend but still didn't find the mistake :( – FormaL Jan 15 '14 at 09:14
  • [link](http://pastebin.com/XyWKticD) working on this user controller but still the same mistake of else & elseif all mess up – FormaL Jan 15 '14 at 09:41
  • [link](http://stackoverflow.com/questions/21133873/parse-error-codeigniter-unexpected-else-and-else-if) I posted question here please check & suggest. – FormaL Jan 15 '14 at 09:44
  • [link](http://stackoverflow.com/questions/21155773/codeigniter-unique-value-error-display) – FormaL Jan 16 '14 at 07:30
1

Try this code. It's a bit cleaner and has indenting which makes it easier to see what's going on.

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

class Welcome extends CI_Controller {

    public function index()
    {
        $this->load->library('user_agent');
        $this->load->helper('url');

        if ($this->agent->is_mobile()) {

            if ($this->input->get("lang") =="en"){
                $this->load->view('m_english_signup');
            }else{
                $this->load->view('m_arabic_signup');
            }

        }else {

            if ($this->input->get("lang") =="en"){
                $this->load->view('d_english_signup');
            }else{
                $this->load->view('d_arabic_signup');
            }
        }
    }
}
ajtrichards
  • 26,991
  • 13
  • 84
  • 93
1

Try this

class Welcome extends CI_Controller {
public function index()
{
    $this->load->library('user_agent');
    $this->load->helper('url');

    if ($this->input->get("lang") =="en"){
        if ($this->agent->is_mobile()) {
            $this->load->view('m_english_signup');
        }
        else {
            $this->load->view('d_english_signup');
        }
    }

else if($this->agent->is_mobile())
     {
        $this->load->view('m_arabic_signup');
}
else {
    $this->load->view('d_arabic_signup');
}
}
}
Nilesh
  • 422
  • 1
  • 4
  • 21
  • Nilesh, yes you are right i mix if & else if and i use this code problem fixed, wait for 6 minutes then i will accept your answer. – FormaL Jan 15 '14 at 09:02
  • [link](http://stackoverflow.com/questions/21155773/codeigniter-unique-value-error-display) – FormaL Jan 16 '14 at 07:30
1

If single line in if else then there is no {}

like this 

if(condition)
   $this->agent->is_mobile();  //statement
else
   $this->agent->is_mobile();   //statement

otherwise

if(condition)
{
   $this->agent->is_mobile();  //statement
}
else
{
   $this->agent->is_mobile();   //statement
 }
Charles
  • 48,924
  • 13
  • 96
  • 136
Anand Somasekhar
  • 586
  • 11
  • 19
1

Your if-else statements are totally messed up :

class Welcome extends CI_Controller {
    public function index(){
        $this->load->library('user_agent');
        $this->load->helper('url');

        if ($this->input->get("lang") =="en"){
            if ($this->agent->is_mobile()) {
                  $this->load->view('m_english_signup');
            }else {
                  $this->load->view('d_english_signup');
            }
        }else{
            if($this->agent->is_mobile()) {
                  $this->load->view('m_arabic_signup');
            }else{
                  $this->load->view('d_arabic_signup');
            }
        }
    }
}
Roy M J
  • 6,711
  • 6
  • 43
  • 76
1

That error due to unexpected else condition or not properly closed.There are one else not properly closed.And the usage of if else in this code is incorrect and confusing.

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

class Welcome extends CI_Controller {
    public function index()
    {
        $this->load->library('user_agent');
        $this->load->helper('url');

        if ($this->agent->is_mobile())
        {

            if ($this->input->get("lang") =="en"){
                $this->load->view('m_english_signup');
            }else{
                $this->load->view('m_arabic_signup');
            }

        }
        else
        {

            if ($this->input->get("lang") =="en"){
                $this->load->view('d_english_signup');
            }else{
                $this->load->view('d_arabic_signup');
            }
        }
    }
}

Please note that i cant identify what conditions you want.I just clear that error occured.

Adarsh M Pallickal
  • 813
  • 3
  • 16
  • 37
0

You cannot have if-else-else-else logic sequence. The valid is

if-elseif-elseif-...-else

or

if-elseif-elseif

or

if-else

Beside that, your second 'else' was not properly enclosed with brackets.

danisupr4
  • 745
  • 1
  • 8
  • 20