0

I have problem and please help me

I'm getting error in this laravel php file on line 15. what could be wrong?

public function tambahdata() {  

    $data = array(
        'nama' => Input::get('nama'),
        'alamat' => Input::get('alamat'),
        'kelas' => Input::get('kelas'),
    );

    DB::table('siswa')->insert($data);
    return Redirect::to('/read')->with('message','Tambah data berhasil');
}
Martin Gottweis
  • 2,721
  • 13
  • 27
metadata
  • 21
  • 1
  • 1
  • 2
  • 3
    Post full code of the file.......... – Md Mahfuzur Rahman Sep 19 '16 at 19:10
  • 4
    it means that your curly braces aren't paired properly; you've got one-too many `}` somewhere. But it's not in the code you've shown us; it's probably somewhere in the code immediately preceding it. – Spudley Sep 19 '16 at 19:11
  • 2
    Proper code indentation helps find and better still helps stop this happening [Take a quick look at a coding standard](http://www.php-fig.org/psr/psr-2/) for your own benefit. You may be asked to amend this code in a few weeks/months and you will thank me in the end. – RiggsFolly Sep 19 '16 at 19:12
  • Error is not in the code you showed us. – RiggsFolly Sep 19 '16 at 19:13
  • Errors usually have line numbers and file names. The function looks fine, so what code precedes it? – Duane Lortie Sep 19 '16 at 19:16
  • If this function is not contained in a class you would get that error, even if all your braces were matched up properly. `public` is only valid within a class, as far as I know. – Don't Panic Sep 19 '16 at 19:24

1 Answers1

2

It looks like you have two braces before the method declaration, meaning that php interpreter thinks that the class is finished, it isn't expecting more method declarations.


You probably have something like this:

<?php
class Something {
    public function someMethod() {
        // Some code
    }} // <------- An extra closing brace. PHP thinks that the class is over and isn't expecting the 'public' keyword, which the next thing in your code

    public function tambahdata() {  
        $data = array(
                'nama' => Input::get('nama'),
                'alamat' => Input::get('alamat'),
                'kelas' => Input::get('kelas'),
            );

        DB::table('siswa')->insert($data);
        return Redirect::to('/read')->with('message','Tambah data berhasil');
    }
}
Xymanek
  • 1,357
  • 14
  • 25