0

Getting a strange error with trying to insert a file 'image' and a text field 'desc'

Blade

{{ Form::file('image') }}</br>
{{ Form::label('desc', trans('Description of the Image')) }}
{{ Form::text('desc', Input::old('desc'), array('id' => 'desc','name' => 'desc', 'class' => 'form-control')) }}
{{ Form::hidden('title-id', $title['id']) }}

Controller

  public function uploadImage()
    {
        $input = array('image' => Input::file('image'), 'desc' => Input::get('desc'), 'title-id' => Input::get('title-id'));

        $this->title->uploadImage($input);

        return Redirect::back()->withSuccess( trans('main.uploaded image success') );
    }

DBWriter

public function uploadImage(array $input)
    {   
        $title = $this->title->find($input['title-id']);
        $name  = str_random(25);
        $insert = array('local' => asset('assets/images/'.$name.'.jpg'), 
                        'desc' => $input['desc'], 
                        'title_id' => $input['title-id']);

        $this->images->saveTitleImage($input, $name);
        $this->dbWriter->compileInsert('images', $insert)->save();

        Event::fire('Titles.Modified', array($input['title-id']));
    }

Error:

Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'desc,title_id) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE local = values(local), d' at line 1 (SQL: INSERT INTO images (local,desc,title_id) VALUES (/assets/images/o00U6rVZPDbkkKUHjDWajHYUO.jpg, sdsd, 1) ON DUPLICATE KEY UPDATE local = values(local), desc = values(desc), title_id = values(title_id))
4
  • 1
    You're not supposed to use desc as a column name, as it's a reserved keyword in mysql, read more here Commented Mar 18, 2014 at 10:06
  • omg I never knew that I was at this for ages trying to figure it out Commented Mar 18, 2014 at 10:16
  • 1
    Let us know if changing it solved the problem :) Commented Mar 18, 2014 at 10:19
  • Glad I could help. I wrote an answer so the question wouldn't remain unanswered - you can accept it if you like :) Commented Mar 19, 2014 at 7:05

1 Answer 1

1

You shouldn't use desc as a column name, because it's a reserved keyword in MySQL.

To fix it, just change columns name (eg. for description) and change your $insert to:

$insert = array('local' => asset('assets/images/'.$name.'.jpg'), 'description' => $input['desc'], 'title_id' => $input['title-id']);

You can read more about MySQLa reserved keywords here

Sign up to request clarification or add additional context in comments.

Comments

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.