Reputation: 457
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))
Upvotes: 0
Views: 1083
Reputation: 3664
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
Upvotes: 1