3

So I'm using this DB facade and eloquent in updating table column

$affectedRows = DB::table('Users')
            ->where('Phone',$phonenumber)
            ->update(['IsActivated' => 'Y']);

or this one:

$affectedRows = Users::where('Phone','=',$phonenumber)
->update(['IsActivated' => 'Y']);

but I encountered this error when I access the url

 <span class="exception_message">SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' (SQL: select * from `users` where (`0` = Phone and `1` = = and `2` = 0000000000) limit 1)</span>
16
  • What is the value of $phonenumber when you print it out? Maybe it is an array and not a number? Commented Apr 24, 2017 at 14:45
  • @Jack the phonenumber value is 0000000000 it's a varchar. ps. I change the phonenumber to 0000000000 since it's my personal number :) Commented Apr 24, 2017 at 14:49
  • Can you give the table definition? Commented Apr 24, 2017 at 14:49
  • 1
    @iamji Can you try replacing $phonenumber with '000000' ? Commented Apr 24, 2017 at 16:19
  • 1
    @Jack tried replacing $phonenumber with '00000' and the update is successful. Anyways restarted mysql service today and tried accessing the /url , guess what it 's already fixed. Commented Apr 26, 2017 at 12:56

2 Answers 2

3

Can you try using

$affectedRows = Users::where('Phone',$phonenumber)->update(['IsActivated' => 'Y']);
Sign up to request clarification or add additional context in comments.

3 Comments

Yes this one : SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' (SQL: select * from users where (0 = Phone and 1 = = and 2 = 0000000000) limit 1)
Can you check the line number of the error. Make sure there are no other attempts to fetch the user in the same page as well
It's in Connection.php line 647, There's no other fetching attempts since I'm using postman in accessing the URL
1

Try these in this exact order and tell us at what commands give an error. Mind I use users and phone, not Users and Phone. It won't affect the query. First add these helper lines in your Users model, right above class Users extends Model

/**
 * App\User
 *
 * @property int $id
 * @property string $phone
 * @property-read \App\User $user
 * @method static wherePhone($value)
 * @mixin \Eloquent
 */

$results = DB::table('users')->where('id', '1')->first();
dd($results);
$results = DB::table('users')->where('id', '1')->get();
dd($results);
$results = DB::table('users')->where(['phone' => '000000000000'])->get();
dd($results);
$results = DB::table('users')->where('phone', '000000000000')->get();
dd($results);
$results = DB::table('users')->where('phone', $phonenumber)->get();
dd($results);
$results = DB::table('users')->wherePhone($phonenumber)->get();
dd($results);

If none of these work, then there is a problem with your model. As no results can be found, an update is impossible. You can inter-exchange DB::table('users')->where(...) with Users::where(...)

Did you by any change called your User model Users.php instead of User.php? I had your problem a while ago but can't really remember what the cause was. It had to do with the User model settings.

3 Comments

Let me try that and btw I'm using User.php.
Hi Dimitri tried the above code and it was all successful. Thank you for your response and I'm sorry for the late response. Tried to restart mysql today and now I was able to update the column
Pleasure bro, happy you found a way out. It was a strange error you were encountering.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.