Rika Rika - 1 month ago 12
MySQL Question

SQLSTATE[42S22]: Column not found: 1054 Unknown column '1' in 'field list' (SQL: select `1` from `phonebooks`)

When i'm try to pass data to edit page then i got this error.Please help me

QueryException in Connection.php line 729:
SQLSTATE[42S22]: Column not found: 1054 Unknown column '1' in 'field list' (SQL: select

1
from
phonebooks
)


PhonebookController.php

public function edit($id)
{
$data = Phonebooks::all($id);
echo"$data";
return view('phonebook.edit', compact('$data'));
}


edit.blade.php

<html>
<body>
<form method="POST" action="{{ URL::to('phonebook') }}" >
<input type="text" name="id" value="{{$id}}"/>
<input type="text" name="phoneNo" value="{{old('phoneNo')}}"/>
<input type="text" name="email" value="{{old('email')}}" />
<input type="submit" value="Save"/>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>

</body>
</html>

Answer Source

You should try this:

 public function edit($id)
        {
            $data = Phonebooks::find($id);

            return view('phonebook.edit', compact('data'));
        }

<html>
    <body>
        <form method="POST" action="{{ URL::to('phonebook') }}" >
            <input type="text" name="id" value="{{$data->id}}"/>
            <input type="text" name="phoneNo" value="{{old('phoneNo')}}"/>
            <input type="text" name="email" value="{{old('email')}}" />
            <input type="submit" value="Save"/>
            <input type="hidden" name="_token" value="{{ csrf_token() }}">
        </form>

    </body>
</html>

Hope this work for you !!!