the tao
the tao

Reputation: 341

Getting mysql syntax error, do not see whats wrong

Using this statement to make a call to database. Getting error, not sure what I am doing wrong here. Says unknown column, but kns2184 is not column name it is field in column.

$sql = "update p4p.users_csv_import
set is_dupe=".(int)(1)." where users_csv_import.username=".$user_name;
$this->db->query($sql);

This is my error:

Error Number: 1054

Unknown column 'kns2184' in 'where clause'

update p4p.users_csv_import set is_dupe=1 where users_csv_import.username=kns2184

Filename: /Applications/MAMP/htdocs/models/user_import_model.php

Line Number: 47

Upvotes: 0

Views: 62

Answers (1)

DaSourcerer
DaSourcerer

Reputation: 6606

You need to quote strings like so:

$sql = "update p4p.users_csv_import
set is_dupe=".(int)(1)." where users_csv_import.username='".$user_name."'";

I highly suggest you look into PDO and parameter binding, though. String concatenation is no safe way to construct SQL queries.

Upvotes: 2

Related Questions