Tmas
Tmas

Reputation: 55

SQLite gives me a no such column error, with the column being the value of a variable I'm trying to store into the table

When I run the following query, SQLite tells me that there is no such column "test", where "test" is the value in the variable $entryname. I want to store $entryname into the name column, not 'name' into $entryname. Does anyone know how to do this?

$query = 'INSERT INTO files (name, description, filename) VALUES (' . $entryname . ', ' . $entrydescription . ', ' . $filename . ')';

Upvotes: 1

Views: 3323

Answers (1)

Jason McCreary
Jason McCreary

Reputation: 73031

You need to quote your string values. They are getting interpreted as a SQLite variable otherwise.

Try the following:

$query = "INSERT INTO files (name, description, filename) VALUES ('" . $entryname . "', '" . $entrydescription . "', '" . $filename . "')";

You should also look into preventing SQL Injection.

Upvotes: 3

Related Questions