1

I'm using ajax to update the database when I drag/drop an element from a nested list. But The query is getting the parameter I pass AS column name.

Code inside my Model:

public static function atualiza_drag($disc, $professor, $old)
    {
        DB::insert('INSERT INTO disciplina_professor (disciplina_id, professor_id) VALUES (`$disc`, `$professor`)');        
        DB::delete("DELETE FROM disciplina_professor WHERE professor_id = `$old`");
    }

The Error:

local.ERROR: exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column '3' in 'field list'

3 is the ID I got from ajax but instead of using this as parameter it's using as a column name and I cant find out why.

1 Answer 1

2

Please remove grave accent (`) from the variables.

Here it should looks like

public static function atualiza_drag($disc, $professor, $old)
    {
        DB::insert('INSERT INTO disciplina_professor (disciplina_id, professor_id) VALUES ($disc, $professor)');        
        DB::delete('DELETE FROM disciplina_professor WHERE professor_id = $old');
    }

Note: If you use single quote (') in your insert then do also use single quote in your delete.

Characters and symbols names
Single qoute = '
Grave accent = `

Resources
http://laravel.com/docs/5.1/database
http://www.lookuptables.com/
http://www.ascii.cl/htmlcodes.htm

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

1 Comment

Removed the Grave accent was right. But I cant use single quote, PHP won't parse that as a variable. But it seems to do the job. I'll test and be right back.

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.